From: Todd C. Miller Date: Wed, 12 May 2010 15:13:40 +0000 (-0400) Subject: Avoid a potential race condition if SIGCHLD is received immediately X-Git-Tag: SUDO_1_8_0~639 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=396317ffe9203fe9ba908ee1f52d8beb4b9a789f;p=sudo Avoid a potential race condition if SIGCHLD is received immediately before we call select(). --- diff --git a/src/script.c b/src/script.c index 18fc0f04b..e3425cc14 100644 --- a/src/script.c +++ b/src/script.c @@ -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)