2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-30 13:58:05 +00:00

If waitpid() returns 0 or -1, display a warning, this should never happen.

Add a check for unhandled wait status (also should never happen).
This commit is contained in:
Todd C. Miller
2016-07-28 06:16:43 -06:00
parent 2b150925dc
commit 383debee9f

View File

@@ -1157,9 +1157,14 @@ handle_sigchld(int backchannel, struct command_status *cstat)
do { do {
pid = waitpid(cmnd_pid, &status, WUNTRACED|WCONTINUED|WNOHANG); pid = waitpid(cmnd_pid, &status, WUNTRACED|WCONTINUED|WNOHANG);
} while (pid == -1 && errno == EINTR); } while (pid == -1 && errno == EINTR);
if (pid <= 0) { switch (pid) {
case 0:
errno = ECHILD;
/* FALLTHROUGH */
case -1:
sudo_debug_printf(SUDO_DEBUG_DIAG, sudo_debug_printf(SUDO_DEBUG_DIAG,
"waitpid returned %d, expected pid %d", pid, cmnd_pid); "waitpid returned %d, expected pid %d", pid, cmnd_pid);
sudo_warn(U_("%s: %s"), __func__, "waitpid");
debug_return_bool(false); debug_return_bool(false);
} }
@@ -1168,18 +1173,22 @@ handle_sigchld(int backchannel, struct command_status *cstat)
} else if (WIFSTOPPED(status)) { } else if (WIFSTOPPED(status)) {
if (sig2str(WSTOPSIG(status), signame) == -1) if (sig2str(WSTOPSIG(status), signame) == -1)
snprintf(signame, sizeof(signame), "%d", WSTOPSIG(status)); snprintf(signame, sizeof(signame), "%d", WSTOPSIG(status));
sudo_debug_printf(SUDO_DEBUG_INFO, "command (%d) stopped, SIG%s", sudo_debug_printf(SUDO_DEBUG_INFO, "%s: command (%d) stopped, SIG%s",
cmnd_pid, signame); __func__, cmnd_pid, signame);
} else if (WIFSIGNALED(status)) { } else if (WIFSIGNALED(status)) {
if (sig2str(WTERMSIG(status), signame) == -1) if (sig2str(WTERMSIG(status), signame) == -1)
snprintf(signame, sizeof(signame), "%d", WTERMSIG(status)); snprintf(signame, sizeof(signame), "%d", WTERMSIG(status));
sudo_debug_printf(SUDO_DEBUG_INFO, "command (%d) killed, SIG%s", sudo_debug_printf(SUDO_DEBUG_INFO, "%s: command (%d) killed, SIG%s",
cmnd_pid, signame); __func__, cmnd_pid, signame);
alive = false;
} else if (WIFEXITED(status)) {
sudo_debug_printf(SUDO_DEBUG_INFO, "%s: command (%d) exited: %d",
__func__, cmnd_pid, WEXITSTATUS(status));
alive = false; alive = false;
} else { } else {
sudo_debug_printf(SUDO_DEBUG_INFO, "command (%d) exited: %d", sudo_debug_printf(SUDO_DEBUG_WARN,
cmnd_pid, WEXITSTATUS(status)); "%s: unexpected wait status %d for command (%d)",
alive = false; __func__, status, cmnd_pid);
} }
/* Don't overwrite execve() failure with child exit status. */ /* Don't overwrite execve() failure with child exit status. */