summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/popen.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1997-09-11 18:51:04 +0000
committerderaadt <deraadt@openbsd.org>1997-09-11 18:51:04 +0000
commit1703df5025350e2edb2e6486cb4d3e678f393ab3 (patch)
tree7d118a61a8d696fc23adb9d85220767b3d4993e6 /lib/libc/gen/popen.c
parentactivate sun3 SCSI DVMA (diff)
downloadwireguard-openbsd-1703df5025350e2edb2e6486cb4d3e678f393ab3.tar.xz
wireguard-openbsd-1703df5025350e2edb2e6486cb4d3e678f393ab3.zip
make popen() safe for a real vfork()
Diffstat (limited to 'lib/libc/gen/popen.c')
-rw-r--r--lib/libc/gen/popen.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index 21dac231b59..561a45e9bba 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: popen.c,v 1.8 1997/08/24 21:25:46 millert Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.9 1997/09/11 18:51:04 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -89,12 +89,14 @@ popen(program, type)
return (NULL);
/* NOTREACHED */
case 0: /* Child. */
+ {
+ struct pid *pcur;
/*
* because vfork() instead of fork(), must leak FILE *,
* but luckily we are terminally headed for an execl()
*/
- for (cur = pidlist; cur; cur = cur->next)
- close(fileno(cur->fp));
+ for (pcur = pidlist; pcur; pcur = pcur->next)
+ close(fileno(pcur->fp));
if (*type == 'r') {
int tpdes1 = pdes[1];
@@ -119,6 +121,7 @@ popen(program, type)
execl(_PATH_BSHELL, "sh", "-c", program, NULL);
_exit(127);
/* NOTREACHED */
+ }
}
/* Parent; assume fdopen can't fail. */