diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2019-01-19 04:15:57 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2019-01-19 04:15:57 +0000 |
commit | dce713c2b979d24a07bda626739b4c5d68575567 (patch) | |
tree | a293c21a31fff087c585e37904b9c50022900177 /usr.bin | |
parent | f95d4e5933bc5af5073ea332addc157c01d12a8d (diff) |
Print an \r in front of the password prompt so parts of a password
that was entered too early are likely clobbered by the prompt.
Idea from doas.
from and ok djm
"i like it" deraadt
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ssh/readpass.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/usr.bin/ssh/readpass.c b/usr.bin/ssh/readpass.c index 521a4cc10a6..d40d5da4923 100644 --- a/usr.bin/ssh/readpass.c +++ b/usr.bin/ssh/readpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readpass.c,v 1.52 2018/07/18 11:34:04 dtucker Exp $ */ +/* $OpenBSD: readpass.c,v 1.53 2019/01/19 04:15:56 tb Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. * @@ -114,7 +114,7 @@ ssh_askpass(char *askpass, const char *msg) char * read_passphrase(const char *prompt, int flags) { - char *askpass = NULL, *ret, buf[1024]; + char cr = '\r', *askpass = NULL, *ret, buf[1024]; int rppflags, use_askpass = 0, ttyfd; rppflags = (flags & RP_ECHO) ? RPP_ECHO_ON : RPP_ECHO_OFF; @@ -128,9 +128,16 @@ read_passphrase(const char *prompt, int flags) } else { rppflags |= RPP_REQUIRE_TTY; ttyfd = open(_PATH_TTY, O_RDWR); - if (ttyfd >= 0) + if (ttyfd >= 0) { + /* + * If we're on a tty, ensure that show the prompt at + * the beginning of the line. This will hopefully + * clobber any password characters the user has + * optimistically typed before echo is disabled. + */ + (void)write(ttyfd, &cr, 1); close(ttyfd); - else { + } else { debug("read_passphrase: can't open %s: %s", _PATH_TTY, strerror(errno)); use_askpass = 1; |