From 2b562522105725f804fc167026265ab424aea7d2 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 8 Oct 2018 06:47:53 -0600 Subject: [PATCH] Handle EOF on password input when pwfedback is enabled. --- lib/util/term.c | 2 ++ src/tgetpass.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/util/term.c b/lib/util/term.c index 657fb6605..99d63e6ea 100644 --- a/lib/util/term.c +++ b/lib/util/term.c @@ -97,6 +97,7 @@ static struct termios term, oterm; static int changed; /* tgetpass() needs to know the erase and kill chars for cbreak mode. */ +__dso_public int sudo_term_eof; __dso_public int sudo_term_erase; __dso_public int sudo_term_kill; @@ -232,6 +233,7 @@ sudo_term_cbreak_v1(int fd) term.c_cc[VSTATUS] = _POSIX_VDISABLE; #endif if (tcsetattr_nobg(fd, TCSASOFT|TCSADRAIN, &term) == 0) { + sudo_term_eof = term.c_cc[VEOF]; sudo_term_erase = term.c_cc[VERASE]; sudo_term_kill = term.c_cc[VKILL]; changed = 1; diff --git a/src/tgetpass.c b/src/tgetpass.c index 6956c0590..939fe48ad 100644 --- a/src/tgetpass.c +++ b/src/tgetpass.c @@ -302,7 +302,7 @@ sudo_askpass(const char *askpass, const char *prompt) debug_return_str_masked(pass); } -extern int sudo_term_erase, sudo_term_kill; +extern int sudo_term_eof, sudo_term_erase, sudo_term_kill; static char * getln(int fd, char *buf, size_t bufsiz, int feedback) @@ -323,7 +323,10 @@ getln(int fd, char *buf, size_t bufsiz, int feedback) if (nr != 1 || c == '\n' || c == '\r') break; if (feedback) { - if (c == sudo_term_kill) { + if (c == sudo_term_eof) { + nr = 0; + break; + } else if (c == sudo_term_kill) { while (cp > buf) { if (write(fd, "\b \b", 3) == -1) break; -- 2.40.0