From 356e74e1dbd9871287bd0dfb4a99efc02a82ed7d Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 24 May 2016 11:16:44 -0600 Subject: [PATCH] Don't read from stdin when flushing final buffers in blocking mode. Reading from the pipe can block too if the other end is not closed. --- NEWS | 4 ++-- src/exec_pty.c | 15 ++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 3f243c6be..2971fa982 100644 --- a/NEWS +++ b/NEWS @@ -30,8 +30,8 @@ What's new in Sudo 1.8.17 * SELinux support, which was broken in 1.8.16, has been repaired. - * Fixed a bug when logging I/O where all buffers might not get - flushed at exit when reading from standard input. + * Fixed a bug when logging I/O where all output buffers might not + get flushed at exit. * Forward slashes are no longer escaped in the JSON output of "visudo -x". This was never required by the standard and not diff --git a/src/exec_pty.c b/src/exec_pty.c index 2179ac50f..3437e2772 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -1024,9 +1024,9 @@ del_io_events(bool nonblocking) (void) sudo_ev_loop(evbase, SUDO_EVLOOP_NONBLOCK); /* - * If not in non-blocking mode, make sure we flush pipes completely. - * We don't want to read from the pty since that might block and - * the command is no longer running anyway. + * If not in non-blocking mode, make sure we flush write buffers. + * We don't want to read from the pty or stdin since that might block + * and the command is no longer running anyway. */ if (!nonblocking) { /* Clear out iobufs from event base. */ @@ -1038,13 +1038,6 @@ del_io_events(bool nonblocking) } SLIST_FOREACH(iob, &iobufs, entries) { - /* Only flush from stdin (pipe). */ - if (iob->revent != NULL && sudo_ev_get_fd(iob->revent) == SFD_STDIN) { - if (iob->len != sizeof(iob->buf)) { - if (sudo_ev_add(evbase, iob->revent, NULL, false) == -1) - sudo_fatal(U_("unable to add event to queue")); - } - } /* Flush any write buffers with data in them. */ if (iob->wevent != NULL) { if (iob->len > iob->off) { @@ -1055,7 +1048,7 @@ del_io_events(bool nonblocking) } (void) sudo_ev_loop(evbase, 0); - /* We should now have flushed all buffers. */ + /* We should now have flushed all write buffers. */ SLIST_FOREACH(iob, &iobufs, entries) { if (iob->wevent != NULL) { if (iob->len > iob->off) { -- 2.40.0