Skip to content

Commit 77fe6ae

Browse files
committed
Use TCSAFLUSH not TCSADRAIN when disabling echo
A long time ago this was changed from TCSAFLUSH to TCSADRAIN due to some systems having problems with TCSAFLUSH. That should no longer be a concern. Using TCSAFLUSH ensures that password input that has been received by the kernel, but not yet read by sudo, will be discarded and not echoed.
1 parent 82ebb1e commit 77fe6ae

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

include/sudo_util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ extern int (*sudo_printf)(int msg_type, const char * restrict fmt, ...);
342342
sudo_dso_public bool sudo_isatty_v1(int fd, struct stat *sbp);
343343
#define sudo_isatty(_a, _b) sudo_isatty_v1((_a), (_b))
344344
sudo_dso_public bool sudo_term_cbreak_v1(int fd);
345-
#define sudo_term_cbreak(_a) sudo_term_cbreak_v1((_a))
345+
sudo_dso_public bool sudo_term_cbreak_v2(int fd, bool flush);
346+
#define sudo_term_cbreak(_a, _b) sudo_term_cbreak_v2((_a), (_b))
346347
sudo_dso_public bool sudo_term_copy_v1(int src, int dst);
347348
#define sudo_term_copy(_a, _b) sudo_term_copy_v1((_a), (_b))
348349
sudo_dso_public bool sudo_term_noecho_v1(int fd);

lib/util/term.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ sudo_term_noecho_v1(int fd)
244244
#ifdef VSTATUS
245245
term.c_cc[VSTATUS] = _POSIX_VDISABLE;
246246
#endif
247-
if (tcsetattr_nobg(fd, TCSASOFT|TCSADRAIN, &term) == -1) {
247+
if (tcsetattr_nobg(fd, TCSASOFT|TCSAFLUSH, &term) == -1) {
248248
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
249249
"%s: tcsetattr(%d)", __func__, fd);
250250
goto unlock;
@@ -358,8 +358,9 @@ sudo_term_raw_v1(int fd, unsigned int flags)
358358
* Returns true on success or false on failure.
359359
*/
360360
bool
361-
sudo_term_cbreak_v1(int fd)
361+
sudo_term_cbreak_v2(int fd, bool flush)
362362
{
363+
const int flags = flush ? (TCSASOFT|TCSAFLUSH) : (TCSASOFT|TCSADRAIN);
363364
struct termios term = { 0 };
364365
bool ret = false;
365366
debug_decl(sudo_term_cbreak, SUDO_DEBUG_UTIL);
@@ -382,7 +383,7 @@ sudo_term_cbreak_v1(int fd)
382383
#ifdef VSTATUS
383384
term.c_cc[VSTATUS] = _POSIX_VDISABLE;
384385
#endif
385-
if (tcsetattr_nobg(fd, TCSASOFT|TCSADRAIN, &term) == -1) {
386+
if (tcsetattr_nobg(fd, flags, &term) == -1) {
386387
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
387388
"%s: tcsetattr(%d)", __func__, fd);
388389
goto unlock;
@@ -399,6 +400,12 @@ sudo_term_cbreak_v1(int fd)
399400
debug_return_bool(ret);
400401
}
401402

403+
bool
404+
sudo_term_cbreak_v1(int fd)
405+
{
406+
return sudo_term_cbreak_v2(fd, false);
407+
}
408+
402409
/*
403410
* Copy terminal settings from one descriptor to another.
404411
* We cannot simply copy the struct termios as src and dst may be

lib/util/util.exp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ sudo_strtomode_v1
159159
sudo_strtomode_v2
160160
sudo_strtonum
161161
sudo_term_cbreak_v1
162+
sudo_term_cbreak_v2
162163
sudo_term_copy_v1
163164
sudo_term_eof
164165
sudo_term_erase

src/tgetpass.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ tgetpass(const char *prompt, int timeout, unsigned int flags,
185185
if (!ISSET(flags, TGP_ECHO)) {
186186
for (;;) {
187187
if (ISSET(flags, TGP_MASK))
188-
neednl = feedback = sudo_term_cbreak(input);
188+
neednl = feedback = sudo_term_cbreak(input, true);
189189
else
190190
neednl = sudo_term_noecho(input);
191191
if (neednl || errno != EINTR)

0 commit comments

Comments
 (0)