]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_passphrase: Fix reading password without TTY
authorJouni Malinen <jouni.malinen@oss.qualcomm.com>
Mon, 26 Jan 2026 17:02:03 +0000 (19:02 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 26 Jan 2026 17:02:03 +0000 (19:02 +0200)
Terminal echo disabling ended up breaking the cases where a password is
read from a file redirection or pipe. Fix this by skipping that change
if there is no TTY.

Fixes: 5102d7411f01 ("wpa_passphrase: Disable terminal echo when reading from stdin")
Signed-off-by: Jouni Malinen <jouni.malinen@oss.qualcomm.com>
wpa_supplicant/wpa_passphrase.c

index cfab4f1b55512d40d686d89cecbaaf35dbdc5a31..704a23353ea1cd332080c24d44c0497786c056c0 100644 (file)
@@ -33,10 +33,14 @@ int main(int argc, char *argv[])
        if (argc > 2) {
                passphrase = argv[2];
        } else {
-               bool ctrl_echo;
+               bool ctrl_echo, notty = false;
 
                fprintf(stderr, "# reading passphrase from stdin\n");
                if (tcgetattr(STDIN_FILENO, &term) < 0) {
+                       if (errno == ENOTTY) {
+                               notty = true;
+                               goto read_pw;
+                       }
                        perror("tcgetattr");
                        return 1;
                }
@@ -46,12 +50,14 @@ int main(int argc, char *argv[])
                        perror("tcsetattr:error disabling echo");
                        return 1;
                }
+       read_pw:
                if (fgets(buf, sizeof(buf), stdin) == NULL) {
                        fprintf(stderr, "Failed to read passphrase\n");
                        return 1;
                }
                term.c_lflag |= ECHO;
-               if (ctrl_echo && tcsetattr(STDIN_FILENO, TCSANOW, &term) < 0) {
+               if (!notty &&
+                   ctrl_echo && tcsetattr(STDIN_FILENO, TCSANOW, &term) < 0) {
                        perror("tcsetattr:error enabling echo");
                        return 1;
                }