From: guenther Date: Fri, 23 Oct 2015 04:52:21 +0000 (+0000) Subject: Fix waitpid() loop again: do the errno check only if waitpid() returns -1 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b2251c561ddd2e76d7c69c6dc0b22299923fe7c4;p=openbsd Fix waitpid() loop again: do the errno check only if waitpid() returns -1 and check WIFEXITED() only if it returns != -1. Delete the logging of errors other than ECHILD: EFAULT and EINVAL are impossible here. ok deraadt@ millert@ --- diff --git a/lib/libc/gen/auth_subr.c b/lib/libc/gen/auth_subr.c index 0df70c4bf2c..70c9160986e 100644 --- a/lib/libc/gen/auth_subr.c +++ b/lib/libc/gen/auth_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth_subr.c,v 1.46 2015/10/22 23:55:51 mmcc Exp $ */ +/* $OpenBSD: auth_subr.c,v 1.47 2015/10/23 04:52:21 guenther Exp $ */ /* * Copyright (c) 2000-2002,2004 Todd C. Miller @@ -896,17 +896,17 @@ auth_call(auth_session_t *as, char *path, ...) as->index = 0; _auth_spool(as, pfd[0]); close(pfd[0]); - status = 0; - while (waitpid(pid, &status, 0) == -1 && errno == EINTR) - ; - if (pid < 0) { - if (errno != ECHILD) { - syslog(LOG_ERR, "%s: waitpid: %m", path); - warnx("internal failure"); - goto fail; + do { + if (waitpid(pid, &status, 0) != -1) { + if (!WIFEXITED(status)) + goto fail; + break; } - } else if (!WIFEXITED(status)) - goto fail; + /* + * could get ECHILD if it was waited for by + * another thread or from a signal handler + */ + } while (errno == EINTR); } /*