]> diplodocus.org Git - nmh/commitdiff
mhlsbr.c: Don't read(2) from fileno(3) of stdout.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sat, 16 Sep 2017 21:58:11 +0000 (22:58 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 17 Sep 2017 12:47:46 +0000 (13:47 +0100)
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.

uip/mhlsbr.c

index 9b7cdd4925d8cfdbbc1175031ce7c9a0fc5d30db..83cef9a2929cbd10882afea5305690a7c4d516df 100644 (file)
@@ -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')) {