From aed123bb7bc3b86f0aa45d5b600229cc174ef5f3 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 7 Aug 2001 19:34:12 +0000 Subject: Do the memset only if tcgetattr() fails just in case the failed tcgetattr() mucked with the passed in struct termios in some way. --- lib/libc/gen/readpassphrase.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/libc/gen') diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c index 2892f1f4ae4..7a77fb85d97 100644 --- a/lib/libc/gen/readpassphrase.c +++ b/lib/libc/gen/readpassphrase.c @@ -26,7 +26,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.6 2001/08/07 19:29:20 millert Exp $"; +static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.7 2001/08/07 19:34:11 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -82,8 +82,6 @@ readpassphrase(prompt, buf, bufsiz, flags) (void)sigprocmask(SIG_BLOCK, &nset, &oset); /* Turn off echo if possible. */ - memset(&term, 0, sizeof(term)); - memset(&oterm, 0, sizeof(oterm)); if (tcgetattr(input, &oterm) == 0) { memcpy(&term, &oterm, sizeof(term)); if (!(flags & RPP_ECHO_ON) && (term.c_lflag & ECHO)) @@ -91,6 +89,9 @@ readpassphrase(prompt, buf, bufsiz, flags) if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) term.c_cc[VSTATUS] = _POSIX_VDISABLE; (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); + } else { + memset(&term, 0, sizeof(term)); + memset(&oterm, 0, sizeof(oterm)); } (void)write(output, prompt, strlen(prompt)); -- cgit v1.2.3