summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-09-29 16:29:49 +0100
committerPeter Stephenson <pws@zsh.org>2017-09-29 16:29:49 +0100
commita1276c88e1137c643bb8055d719afc17cb37bf0f (patch)
tree6269aeef2fc25b601652147a41b1904369f6a624 /Src
parent7cb55668c2b4c559f0cb6a3d72be8eccaa5afa1a (diff)
downloadzsh-a1276c88e1137c643bb8055d719afc17cb37bf0f.tar.gz
zsh-a1276c88e1137c643bb8055d719afc17cb37bf0f.tar.xz
zsh-a1276c88e1137c643bb8055d719afc17cb37bf0f.zip
41789: Don't save fd if -1.
We try to move an fd which isn't opend but it will feel.
This needs handling specially in the new code for marking
saved fd's.
Diffstat (limited to 'Src')
-rw-r--r--Src/exec.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 0d2dc4ebb..780998b1a 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2325,16 +2325,19 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag,
 		     * fd1 may already be closed here, so
 		     * ignore bad file descriptor error
 		     */
-		    if (fdN < 0 && errno != EBADF) {
-			zerr("cannot duplicate fd %d: %e", fd1, errno);
-			mfds[fd1] = NULL;
-			closemnodes(mfds);
-			return;
+		    if (fdN < 0) {
+			if (errno != EBADF) {
+			    zerr("cannot duplicate fd %d: %e", fd1, errno);
+			    mfds[fd1] = NULL;
+			    closemnodes(mfds);
+			    return;
+			}
+		    } else {
+			DPUTS(fdtable[fdN] != FDT_INTERNAL,
+			      "Saved file descriptor not marked as internal");
+			fdtable[fdN] |= FDT_SAVED_MASK;
 		    }
 		    save[fd1] = fdN;
-		    DPUTS(fdtable[fdN] != FDT_INTERNAL,
-			  "Saved file descriptor not marked as internal");
-		    fdtable[fdN] |= FDT_SAVED_MASK;
 		}
 	    }
 	}