summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1999-06-23 10:30:51 +0000
committermillert <millert@openbsd.org>1999-06-23 10:30:51 +0000
commit00dbc66800d080a38a76da46856b1a20bbb7d785 (patch)
treecde3d15f42fe2b7a30e9e3f30bda1c59a2fd2652
parentImproved sysv shared memory. Works with UVM. (diff)
downloadwireguard-openbsd-00dbc66800d080a38a76da46856b1a20bbb7d785.tar.xz
wireguard-openbsd-00dbc66800d080a38a76da46856b1a20bbb7d785.zip
When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file that was redirected. There is probably a better fix for this.
-rw-r--r--bin/ksh/exec.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index 236da3efbfd..d59b5062926 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.17 1999/06/15 01:18:33 millert Exp $ */
+/* $OpenBSD: exec.c,v 1.18 1999/06/23 10:30:51 millert Exp $ */
/*
* execute command tree
@@ -1359,11 +1359,21 @@ iosetup(iop, tp)
}
}
if (do_open) {
+ int nfd;
+
if (Flag(FRESTRICTED) && (flags & O_CREAT)) {
warningf(TRUE, "%s: restricted", cp);
return -1;
}
u = open(cp, flags, 0666);
+ if (u >= 0 && u < 3) {
+ /* Don't reuse stdin/stdout/stderr */
+ nfd = ksh_dupbase(u, 3);
+ if (nfd != -1) {
+ close(u);
+ u = nfd;
+ }
+ }
#ifdef OS2
if (u < 0 && strcmp(cp, "/dev/null") == 0)
u = open("nul", flags, 0666);