From: Ralph Corderoy Date: Sat, 16 Sep 2017 21:58:11 +0000 (+0100) Subject: mhlsbr.c: Don't read(2) from fileno(3) of stdout. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/6fd323cc02e4e90d24e30b8c78a88a55e749556f?ds=inline;hp=4d0110006d4e72f82fb597f170c7d9991f2ca0bf mhlsbr.c: Don't read(2) from fileno(3) of stdout. Remove the assumption that file descriptor 1 is readable. It can be if it, or where it was dup(2)'d from, was opened read/write, e.g. on /dev/tty. But it can easily be arranged with shell re-direction that it isn't, and then the read(2) fails. Pass 0, standard input's file descriptor, instead. Don't use fileno(stdin) as I can't think of a need to support that being non-zero, but its use makes the reader think it might. Bug pre-dates git. --- diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 9b7cdd49..83cef9a2 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -969,7 +969,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) } fflush (stdout); buf[0] = 0; - if (read (fileno (stdout), buf, sizeof(buf)) < 0) { + if (read(0, buf, sizeof(buf)) < 0) { advise ("stdout", "read"); } } @@ -1524,7 +1524,7 @@ putch (char ch, unsigned long flags) putchar ('\007'); fflush (stdout); buf[0] = 0; - if (read (fileno (stdout), buf, sizeof(buf)) < 0) { + if (read(0, buf, sizeof(buf)) < 0) { advise ("stdout", "read"); } if (strchr(buf, '\n')) {