]> diplodocus.org Git - nmh/commitdiff
getpass.c: Don't fileno(NULL) when fopen("/dev/tty") fails.
authorRalph Corderoy <ralph@inputplus.co.uk>
Thu, 7 Sep 2017 09:16:36 +0000 (10:16 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Thu, 7 Sep 2017 09:47:25 +0000 (10:47 +0100)
If stdin is a TTY, but opening it for writing fails, then stdin and
stderr are used as defaults and the TTY doesn't have echo disabled.  The
later test to restore echo just checks if stdin is a TTY and not that it
was opened successfully causing a NULL FILE pointer to be fileno(3)'d.
Fixes da6af9633.  This function's logic remains a bit contorted;  I went
for the minimal fix.

sbr/getpass.c

index 4b24af3c137299c3ce77097e46c6a01ec9bb2964..12805f2fdf8e878b9b4309b99eca222eaf7402ef 100644 (file)
@@ -78,7 +78,7 @@ nmh_getpass(const char *prompt)
     *p++ = ch;
   *p = '\0';
 
     *p++ = ch;
   *p = '\0';
 
-  if (istty) {
+  if (istty && fin != stdin) {
     (void)tcsetattr(fileno(fin), TCSANOW, &oterm);
     rewind(fout);
     (void)fputc('\n', fout);
     (void)tcsetattr(fileno(fin), TCSANOW, &oterm);
     rewind(fout);
     (void)fputc('\n', fout);