]> granicus.if.org Git - sudo/commitdiff
Avoid a potential race condition if SIGCHLD is received immediately
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 12 May 2010 15:13:40 +0000 (11:13 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 12 May 2010 15:13:40 +0000 (11:13 -0400)
before we call select().

src/script.c

index 18fc0f04bbbabc558c3b94594222304b4cb5c9b9..e3425cc14472dd92e5b94ce3531bec853cde2e11 100644 (file)
@@ -766,6 +766,8 @@ script_execve(struct command_details *details, char *argv[], char *envp[],
            }
        }
 
+       if (recvsig[SIGCHLD])
+           continue;
        nready = select(maxfd + 1, fdsr, fdsw, NULL, NULL);
        if (nready == -1) {
            if (errno == EINTR)
@@ -1050,7 +1052,7 @@ script_child(const char *path, char *argv[], char *envp[], int backchannel, int
     zero_bytes(&cstat, sizeof(cstat));
     for (;;) {
        /* Read child status */
-       while (recvsig[SIGCHLD]) {
+       if (recvsig[SIGCHLD]) {
            recvsig[SIGCHLD] = FALSE;
            /* read child status and relay to parent */
            do {
@@ -1087,6 +1089,9 @@ script_child(const char *path, char *argv[], char *envp[], int backchannel, int
        if (errpipe[0] != -1)
            FD_SET(errpipe[0], fdsr);
        maxfd = MAX(errpipe[0], backchannel);
+
+       if (recvsig[SIGCHLD])
+           continue;
        n = select(maxfd + 1, fdsr, NULL, NULL, NULL);
        if (n == -1) {
            if (errno == EINTR)