From a9d83bef026ef5bd117c61db209676f190f7980f Mon Sep 17 00:00:00 2001 From: guenther <> Date: Thu, 16 Jul 2015 02:46:49 +0000 Subject: After reading a password with terminal echo off, restore the terminal to its original state instead of blindly turning echo on. problem reported on the openssl-dev list by William Freeman ok miod@ beck@ --- src/lib/libcrypto/ui/ui_openssl.c | 11 +++++------ src/lib/libssl/src/crypto/ui/ui_openssl.c | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c index a46534e3e5..b3d2971a02 100644 --- a/src/lib/libcrypto/ui/ui_openssl.c +++ b/src/lib/libcrypto/ui/ui_openssl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ui_openssl.c,v 1.23 2014/07/13 00:10:47 deraadt Exp $ */ +/* $OpenBSD: ui_openssl.c,v 1.24 2015/07/16 02:46:49 guenther Exp $ */ /* Written by Richard Levitte (richard@levitte.org) and others * for the OpenSSL project 2001. */ @@ -134,7 +134,7 @@ /* Define globals. They are protected by a lock */ static struct sigaction savsig[NX509_SIG]; -static struct termios tty_orig, tty_new; +static struct termios tty_orig; static FILE *tty_in, *tty_out; static int is_a_tty; @@ -325,7 +325,8 @@ open_console(UI *ui) static int noecho_console(UI *ui) { - memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig)); + struct termios tty_new = tty_orig; + tty_new.c_lflag &= ~ECHO; if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_new) == -1)) return 0; @@ -335,9 +336,7 @@ noecho_console(UI *ui) static int echo_console(UI *ui) { - memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig)); - tty_new.c_lflag |= ECHO; - if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_new) == -1)) + if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_orig) == -1)) return 0; return 1; } diff --git a/src/lib/libssl/src/crypto/ui/ui_openssl.c b/src/lib/libssl/src/crypto/ui/ui_openssl.c index a46534e3e5..b3d2971a02 100644 --- a/src/lib/libssl/src/crypto/ui/ui_openssl.c +++ b/src/lib/libssl/src/crypto/ui/ui_openssl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ui_openssl.c,v 1.23 2014/07/13 00:10:47 deraadt Exp $ */ +/* $OpenBSD: ui_openssl.c,v 1.24 2015/07/16 02:46:49 guenther Exp $ */ /* Written by Richard Levitte (richard@levitte.org) and others * for the OpenSSL project 2001. */ @@ -134,7 +134,7 @@ /* Define globals. They are protected by a lock */ static struct sigaction savsig[NX509_SIG]; -static struct termios tty_orig, tty_new; +static struct termios tty_orig; static FILE *tty_in, *tty_out; static int is_a_tty; @@ -325,7 +325,8 @@ open_console(UI *ui) static int noecho_console(UI *ui) { - memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig)); + struct termios tty_new = tty_orig; + tty_new.c_lflag &= ~ECHO; if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_new) == -1)) return 0; @@ -335,9 +336,7 @@ noecho_console(UI *ui) static int echo_console(UI *ui) { - memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig)); - tty_new.c_lflag |= ECHO; - if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_new) == -1)) + if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_orig) == -1)) return 0; return 1; } -- cgit v1.2.3-55-g6feb