]> granicus.if.org Git - sudo/commitdiff
Go back to reseting io_buffer offset and length (and now also the
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 5 May 2010 20:11:13 +0000 (16:11 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 5 May 2010 20:11:13 +0000 (16:11 -0400)
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.

src/script.c

index 4c774da3d6a45fa9bb77145767b44556aa037922..fd67c80cd022150ca3313b998df24e9263ab730e 100644 (file)
@@ -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;
-                   }
-               }
            }
        }
     }