]> granicus.if.org Git - sudo/commitdiff
In io_callback() make sure we clear SUDO_EV_READ if we close the
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 7 May 2016 20:51:37 +0000 (14:51 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 7 May 2016 20:51:37 +0000 (14:51 -0600)
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.

src/exec_pty.c

index 96e2423b5d7ff63e7d6c51a6954b49bc202deb0e..602eac303d41d95e70f10e00733c11aedbe43749 100644 (file)
@@ -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. */