From: Todd C. Miller Date: Wed, 5 May 2010 20:11:13 +0000 (-0400) Subject: Go back to reseting io_buffer offset and length (and now also the X-Git-Tag: SUDO_1_8_0~661 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3cbbf27e9d91443fe85b0ff9d1163037d6f1c178;p=sudo Go back to reseting io_buffer offset and length (and now also the EOF handling) in the loop we do the FD_SET, not after we drain the buffer after write() since we don't know what order reads and writes will occur in. --- diff --git a/src/script.c b/src/script.c index 4c774da3d..fd67c80cd 100644 --- a/src/script.c +++ b/src/script.c @@ -674,6 +674,16 @@ script_execve(struct command_details *details, char *argv[], char *envp[], FD_SET(sv[0], fdsr); for (iob = iobufs; iob; iob = iob->next) { + if (iob->rfd == -1 && iob->wfd == -1) + continue; + if (iob->off == iob->len) { + iob->off = iob->len = 0; + /* Forward the EOF from reader to writer. */ + if (iob->rfd == -1) { + close(iob->wfd); + iob->wfd = -1; + } + } /* Don't read/write /dev/tty if we are not in the foreground. */ if (iob->rfd != -1 && (ttymode == TERM_RAW || iob->rfd != script_fds[SFD_USERTTY])) { @@ -786,14 +796,6 @@ script_execve(struct command_details *details, char *argv[], char *envp[], } else { iob->off += n; } - if (iob->off == iob->len) { - iob->off = iob->len = 0; - /* Forward the EOF from reader to writer. */ - if (iob->rfd == -1) { - close(iob->wfd); - iob->wfd = -1; - } - } } } }