From: Todd C. Miller Date: Sat, 7 May 2016 20:51:37 +0000 (-0600) Subject: In io_callback() make sure we clear SUDO_EV_READ if we close the X-Git-Tag: SUDO_1_8_17^2~77 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=094854adfee86565230b1a737ae50bef6840c640;p=sudo In io_callback() make sure we clear SUDO_EV_READ if we close the fd. It should not be possible for SUDO_EV_READ to be set when revent is non-NULL but this makes static analyzers happier. Coverity CID 104124. --- diff --git a/src/exec_pty.c b/src/exec_pty.c index 96e2423b5..602eac303 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -562,11 +562,12 @@ io_callback(int fd, int what, void *v) sudo_debug_printf(SUDO_DEBUG_INFO, "unable to write %d bytes to fd %d", iob->len - iob->off, fd); + /* Close reader if there is one. */ if (iob->revent != NULL) { - CLR(what, SUDO_EV_READ); safe_close(sudo_ev_get_fd(iob->revent)); ev_free_by_fd(evbase, sudo_ev_get_fd(iob->revent)); } + CLR(what, SUDO_EV_READ); safe_close(fd); ev_free_by_fd(evbase, fd); break; @@ -592,11 +593,11 @@ io_callback(int fd, int what, void *v) /* Reset buffer if fully consumed. */ if (iob->off == iob->len) { iob->off = iob->len = 0; - /* If reader is gone, close and remove writer; we are done. */ + /* Forward the EOF from reader to writer. */ if (iob->revent == NULL) { + CLR(what, SUDO_EV_READ); safe_close(fd); ev_free_by_fd(evbase, fd); - debug_return; } } /* Re-enable writer if buffer is not empty. */