about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2019-07-02 13:42:53 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2019-07-02 13:42:53 +0100
commit3bdf4d6641fb34d1c2f130abddb847169a793afe (patch)
treeb1c3686749a26212f08bfd8ffea464804f308d86 /Src
parent700ec49581650ea1f0bffacb207a30145e278417 (diff)
downloadzsh-3bdf4d6641fb34d1c2f130abddb847169a793afe.tar.gz
zsh-3bdf4d6641fb34d1c2f130abddb847169a793afe.tar.xz
zsh-3bdf4d6641fb34d1c2f130abddb847169a793afe.zip
44480: Don't automatically close externally visible file descroptors.
These are descriptors marked FDT_EXTERNAL.

Make all sysopen'ed file descriptors FDT_EXTERNAL.

Make =(...) call closem() consistent with other substitutions.

Document file descriptors are left open.
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/system.c4
-rw-r--r--Src/exec.c5
2 files changed, 6 insertions, 3 deletions
diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index 7a4f4ee13..50de59cf9 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -316,7 +316,7 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
     int o, fd, moved_fd, explicit = -1;
     mode_t perms = 0666;
 #if defined(FD_CLOEXEC) && !defined(O_CLOEXEC)
-    int fdflags;
+    int fdflags = 0;
 #endif
 
     if (!OPT_ISSET(ops, 'u')) {
@@ -396,8 +396,8 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
 #endif /* O_CLOEXEC */
 	fcntl(moved_fd, F_SETFD, FD_CLOEXEC);
 #endif /* FD_CLOEXEC */
+    fdtable[moved_fd] = FDT_EXTERNAL;
     if (explicit == -1) {
-	fdtable[moved_fd] = FDT_EXTERNAL;
 	setiparam(fdvar, moved_fd);
 	/* if setting the variable failed, close moved_fd to avoid leak */
 	if (errflag)
diff --git a/Src/exec.c b/Src/exec.c
index 60ab0acf8..2acb2c0bc 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4407,8 +4407,10 @@ closem(int how, int all)
 	    /*
 	     * Process substitution needs to be visible to user;
 	     * fd's are explicitly cleaned up by filelist handling.
+	     * External FDs are managed directly by the user.
 	     */
-	    (all || fdtable[i] != FDT_PROC_SUBST) &&
+	    (all || (fdtable[i] != FDT_PROC_SUBST &&
+		     fdtable[i] != FDT_EXTERNAL)) &&
 	    (how == FDT_UNUSED || (fdtable[i] & FDT_TYPE_MASK) == how)) {
 	    if (i == SHTTY)
 		SHTTY = -1;
@@ -4823,6 +4825,7 @@ getoutputfile(char *cmd, char **eptr)
     }
 
     /* pid == 0 */
+    closem(FDT_UNUSED, 0);
     redup(fd, 1);
     entersubsh(ESUB_PGRP|ESUB_NOMONITOR, NULL);
     cmdpush(CS_CMDSUBST);