From 791aa4b8eef5b21ba07f7b8c6ad2437f942ecc08 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Wed, 27 Nov 2013 20:25:48 +0000 Subject: astoundingly, the read loop has been subtly broken in a variety of ways on big-endian machines for quite a while. Some discussion with millert and guenther to repair it. --- distrib/special/more/more.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'distrib') diff --git a/distrib/special/more/more.c b/distrib/special/more/more.c index 7b2453d18d4..ba972431b6d 100644 --- a/distrib/special/more/more.c +++ b/distrib/special/more/more.c @@ -1,4 +1,4 @@ -/* $OpenBSD: more.c,v 1.33 2013/11/26 21:13:04 deraadt Exp $ */ +/* $OpenBSD: more.c,v 1.34 2013/11/27 20:25:47 deraadt Exp $ */ /* * Copyright (c) 2003 Todd C. Miller @@ -1610,23 +1610,25 @@ handle_signal(void) int readch(void) { - int ch; + unsigned char ch; + int r; - errno = 0; /* We know stderr is hooked up to /dev/tty so this is safe. */ again: - if (read(STDERR_FILENO, &ch, 1) <= 0) { - if (signo != 0) { - if ((ch = handle_signal()) == -1) - goto again; - } else { - if (errno != EINTR) - end_it(); - else - ch = otty.c_cc[VKILL]; - } + switch (read(STDERR_FILENO, &ch, 1)) { + case 1: + return (ch); + case -1: + if (errno != EINTR) + end_it(); + + r = handle_signal(); + if (r == -1) + goto again; + return (r); /* redraw, continue, etc */ + case 0: + end_it(); } - return (ch); } static char BS1 = '\b'; -- cgit v1.2.3