summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2017-08-21 21:41:13 +0000
committerderaadt <deraadt@openbsd.org>2017-08-21 21:41:13 +0000
commit2aeb6b04aa176ef63e3c80e808b0825f52f9d667 (patch)
treef878ca55fb6ebedeea2cc01fc560d344bd407c0c
parentMove the kernel relinking code from /etc/rc into a seperate script (diff)
downloadwireguard-openbsd-2aeb6b04aa176ef63e3c80e808b0825f52f9d667.tar.xz
wireguard-openbsd-2aeb6b04aa176ef63e3c80e808b0825f52f9d667.zip
Use waitpid()/EINTR idiom for the specific pid, rather than generic wait(),
in case the parent process was started with a dangling child. This style ensures any potential parent:child interlock isn't disrupted due to the "wrong" child being waited on first. Then the other other childs can safely zombie. ok millert jca brynet
-rw-r--r--lib/libfuse/fuse.c9
-rw-r--r--usr.bin/calendar/io.c11
-rw-r--r--usr.bin/m4/gnum4.c10
-rw-r--r--usr.bin/passwd/pwd_check.c15
-rw-r--r--usr.bin/sendbug/sendbug.c13
-rw-r--r--usr.bin/tput/tput.c11
-rw-r--r--usr.bin/xinstall/xinstall.c11
-rw-r--r--usr.sbin/radiusd/radiusd_bsdauth.c16
8 files changed, 64 insertions, 32 deletions
diff --git a/lib/libfuse/fuse.c b/lib/libfuse/fuse.c
index 30fd62d4aac..7d50da596f5 100644
--- a/lib/libfuse/fuse.c
+++ b/lib/libfuse/fuse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fuse.c,v 1.28 2016/05/24 19:24:46 okan Exp $ */
+/* $OpenBSD: fuse.c,v 1.29 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
@@ -294,7 +294,7 @@ ifuse_get_signal(unused int num)
child = fork();
if (child < 0)
- return ;
+ return;
f = sigse->args;
if (child == 0) {
@@ -304,7 +304,10 @@ ifuse_get_signal(unused int num)
}
fuse_loop(f);
- wait(&status);
+ while (waitpid(child, &status, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
}
}
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
index 428565dfdae..8abe7996917 100644
--- a/usr.bin/calendar/io.c
+++ b/usr.bin/calendar/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.45 2017/08/10 14:26:31 tb Exp $ */
+/* $OpenBSD: io.c,v 1.46 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -385,6 +385,7 @@ closecal(FILE *fp)
struct stat sbuf;
int nread, pdes[2], status;
char buf[1024];
+ pid_t pid;
if (!doall)
return;
@@ -394,7 +395,7 @@ closecal(FILE *fp)
goto done;
if (pipe(pdes) < 0)
goto done;
- switch (vfork()) {
+ switch ((pid = vfork())) {
case -1: /* error */
(void)close(pdes[0]);
(void)close(pdes[1]);
@@ -421,8 +422,10 @@ closecal(FILE *fp)
(void)write(pdes[1], buf, nread);
(void)close(pdes[1]);
done: (void)fclose(fp);
- while (wait(&status) >= 0)
- ;
+ while (waitpid(pid, &status, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
}
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c
index 4280cb97339..1de66f2fa1b 100644
--- a/usr.bin/m4/gnum4.c
+++ b/usr.bin/m4/gnum4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gnum4.c,v 1.51 2017/06/15 13:48:42 bcallah Exp $ */
+/* $OpenBSD: gnum4.c,v 1.52 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@@ -630,7 +630,7 @@ void
doesyscmd(const char *cmd)
{
int p[2];
- pid_t pid, cpid;
+ pid_t cpid;
char *argv[4];
int cc;
int status;
@@ -668,8 +668,10 @@ doesyscmd(const char *cmd)
} while (cc > 0 || (cc == -1 && errno == EINTR));
(void) close(p[0]);
- while ((pid = wait(&status)) != cpid && pid >= 0)
- continue;
+ while (waitpid(cpid, &status, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
pbstr(getstring());
}
}
diff --git a/usr.bin/passwd/pwd_check.c b/usr.bin/passwd/pwd_check.c
index fcb3dfdeb41..cfdd1f65ed2 100644
--- a/usr.bin/passwd/pwd_check.c
+++ b/usr.bin/passwd/pwd_check.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pwd_check.c,v 1.15 2015/12/09 19:39:10 mmcc Exp $ */
+/* $OpenBSD: pwd_check.c,v 1.16 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Copyright 2000 Niels Provos <provos@citi.umich.edu>
@@ -138,12 +138,14 @@ pwd_check(login_cap_t *lc, char *password)
err(1, "pledge");
for (i = 0; i < sizeof(patterns) / sizeof(*patterns); i++) {
+ int ret;
+
if (regcomp(&rgx, patterns[i].match,
patterns[i].flags) != 0)
continue;
- res = regexec(&rgx, password, 0, NULL, 0);
+ ret = regexec(&rgx, password, 0, NULL, 0);
regfree(&rgx);
- if (res == 0) {
+ if (ret == 0) {
printf("%s\n", patterns[i].response);
exit(1);
}
@@ -181,8 +183,11 @@ pwd_check(login_cap_t *lc, char *password)
}
/* get the return value from the child */
- wait(&child);
- if (WIFEXITED(child) && WEXITSTATUS(child) == 0) {
+ while (waitpid(child, &res, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
+ if (WIFEXITED(res) && WEXITSTATUS(res) == 0) {
free(checker);
return (1);
}
diff --git a/usr.bin/sendbug/sendbug.c b/usr.bin/sendbug/sendbug.c
index b06a823855b..cf3385b46ae 100644
--- a/usr.bin/sendbug/sendbug.c
+++ b/usr.bin/sendbug/sendbug.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sendbug.c,v 1.77 2016/10/18 20:07:35 kettenis Exp $ */
+/* $OpenBSD: sendbug.c,v 1.78 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Written by Ray Lai <ray@cyth.net>.
@@ -277,9 +277,10 @@ editit(const char *pathname)
execv(_PATH_BSHELL, argp);
_exit(127);
}
- while (waitpid(pid, &st, 0) == -1)
+ while (waitpid(pid, &st, 0) == -1) {
if (errno != EINTR)
goto fail;
+ }
if (!WIFEXITED(st))
errno = EINTR;
else
@@ -317,12 +318,13 @@ int
sendmail(const char *pathname)
{
int filedes[2];
+ pid_t pid;
if (pipe(filedes) == -1) {
warn("pipe: unsent report in %s", pathname);
return (-1);
}
- switch (fork()) {
+ switch ((pid = fork())) {
case -1:
warn("fork error: unsent report in %s",
pathname);
@@ -349,7 +351,10 @@ sendmail(const char *pathname)
return (-1);
}
close(filedes[1]);
- wait(NULL);
+ while (waitpid(pid, NULL, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
break;
}
return (0);
diff --git a/usr.bin/tput/tput.c b/usr.bin/tput/tput.c
index 8289ad3d2f3..e3fa82c3812 100644
--- a/usr.bin/tput/tput.c
+++ b/usr.bin/tput/tput.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tput.c,v 1.22 2015/11/16 03:03:28 deraadt Exp $ */
+/* $OpenBSD: tput.c,v 1.23 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -52,6 +52,7 @@
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
+#include <errno.h>
#include <limits.h>
#include <string.h>
@@ -269,9 +270,10 @@ init(void)
size_t len;
char *buf;
int wstatus;
+ pid_t pid;
if (init_prog && !issetugid()) {
- switch (vfork()) {
+ switch (pid = vfork()) {
case -1:
err(4, "vfork");
break;
@@ -281,7 +283,10 @@ init(void)
_exit(127);
break;
default:
- wait(&wstatus);
+ while (waitpid(pid, &wstatus, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
/* parent */
break;
}
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 949835f6bf6..9d866825107 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xinstall.c,v 1.65 2016/05/13 17:51:15 jmc Exp $ */
+/* $OpenBSD: xinstall.c,v 1.66 2017/08/21 21:41:13 deraadt Exp $ */
/* $NetBSD: xinstall.c,v 1.9 1995/12/20 10:25:17 jonathan Exp $ */
/*
@@ -558,11 +558,12 @@ strip(char *to_name)
{
int serrno, status;
char * volatile path_strip;
+ pid_t pid;
if (issetugid() || (path_strip = getenv("STRIP")) == NULL)
path_strip = _PATH_STRIP;
- switch (vfork()) {
+ switch ((pid = vfork())) {
case -1:
serrno = errno;
(void)unlink(to_name);
@@ -572,7 +573,11 @@ strip(char *to_name)
warn("%s", path_strip);
_exit(1);
default:
- if (wait(&status) == -1 || !WIFEXITED(status))
+ while (waitpid(pid, &status, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
+ if (!WIFEXITED(status))
(void)unlink(to_name);
}
}
diff --git a/usr.sbin/radiusd/radiusd_bsdauth.c b/usr.sbin/radiusd/radiusd_bsdauth.c
index fe85ac514a9..7f03a0c41ee 100644
--- a/usr.sbin/radiusd/radiusd_bsdauth.c
+++ b/usr.sbin/radiusd/radiusd_bsdauth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radiusd_bsdauth.c,v 1.7 2015/12/05 13:22:32 claudio Exp $ */
+/* $OpenBSD: radiusd_bsdauth.c,v 1.8 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@@ -61,7 +61,7 @@ struct auth_groupcheck_args {
size_t grouplen;
};
-static void module_bsdauth_main(int, int);
+static pid_t module_bsdauth_main(int, int);
static void module_bsdauth_config_set(void *, const char *, int,
char * const *);
static void module_bsdauth_userpass(void *, u_int, const char *,
@@ -82,12 +82,13 @@ main(int argc, char *argv[])
struct imsg imsg;
ssize_t n;
size_t datalen;
+ pid_t pid;
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pairsock) == -1)
err(EXIT_FAILURE, "socketpair");
pipe_chld = pairsock[1];
- module_bsdauth_main(pairsock[0], pairsock[1]);
+ pid = module_bsdauth_main(pairsock[0], pairsock[1]);
/*
* Privileged process
@@ -201,12 +202,15 @@ group_done:
imsg_flush(&ibuf);
}
imsg_clear(&ibuf);
- wait(&status);
+ while (waitpid(pid, &status, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
exit(WEXITSTATUS(status));
}
-static void
+static pid_t
module_bsdauth_main(int pipe_prnt, int pipe_chld)
{
int i;
@@ -219,7 +223,7 @@ module_bsdauth_main(int pipe_prnt, int pipe_chld)
if (pid > 0) {
close(pipe_prnt);
- return;
+ return (pid);
}
close(pipe_chld);