From: Jouni Malinen Date: Mon, 26 Jan 2026 17:02:03 +0000 (+0200) Subject: wpa_passphrase: Fix reading password without TTY X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e73a8f30868ea36f0f2159c95d9e3d9412d3b821;p=thirdparty%2Fhostap.git wpa_passphrase: Fix reading password without TTY 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 --- diff --git a/wpa_supplicant/wpa_passphrase.c b/wpa_supplicant/wpa_passphrase.c index cfab4f1b5..704a23353 100644 --- a/wpa_supplicant/wpa_passphrase.c +++ b/wpa_supplicant/wpa_passphrase.c @@ -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; }