summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-04-16 21:59:04 +0000
committermillert <millert@openbsd.org>1997-04-16 21:59:04 +0000
commit21cfeb15443287a787445e3a9f20bf3a6f53a7af (patch)
treecc30cfd12d447f83e08256d3fe5b9b3751f830eb
parentadd ext2fs (diff)
downloadwireguard-openbsd-21cfeb15443287a787445e3a9f20bf3a6f53a7af.tar.xz
wireguard-openbsd-21cfeb15443287a787445e3a9f20bf3a6f53a7af.zip
Don't modify variables in the child since we vfork()'d to
get there (address space is shared between parent in child in traditional vfork(2)). From FreeBSD (dyson).
-rw-r--r--lib/libc/gen/popen.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index 56a689806d5..2b667606941 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.3 1996/08/19 08:25:20 tholo Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.4 1997/04/16 21:59:04 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -86,9 +86,15 @@ popen(program, type)
/* NOTREACHED */
case 0: /* Child. */
if (*type == 'r') {
- if (pdes[1] != STDOUT_FILENO) {
- (void)dup2(pdes[1], STDOUT_FILENO);
- (void)close(pdes[1]);
+ /*
+ * We must NOT modify pdes, due to the
+ * semantics of vfork.
+ */
+ int tpdes1 = pdes[1];
+ if (tpdes1 != STDOUT_FILENO) {
+ (void)dup2(tpdes1, STDOUT_FILENO);
+ (void)close(tpdes1);
+ tpdes1 = STDOUT_FILENO;
}
(void) close(pdes[0]);
} else {