Przeglądaj źródła

Per discussion on the mailing list, fix getpass properly.
-Erik

Eric Andersen 22 lat temu
rodzic
commit
caab797645
1 zmienionych plików z 7 dodań i 2 usunięć
  1. 7 2
      libc/unistd/getpass.c

+ 7 - 2
libc/unistd/getpass.c

@@ -61,8 +61,10 @@ getpass (prompt)
       /* Save the old one. */
       s = t;
       /* Tricky, tricky. */
-      t.c_lflag &= ~(ECHO|ICANON|ISIG);
+      t.c_lflag &= ~(ECHO|ISIG);
       tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
+      /* Disable buffering for input FILE to prevent the buffering from flushing. */
+      setvbuf(in, NULL, _IOLBF, 0);
     }
   else
     tty_changed = 0;
@@ -89,8 +91,11 @@ getpass (prompt)
     }
 
   /* Restore the original setting.  */
-  if (tty_changed)
+  if (tty_changed) {
     (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
+    /* Re-enable buffering. */
+    setlinebuf(in);
+  }
 
   if (in != stdin)
     /* We opened the terminal; now close it.  */