Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: fd used for saving redirected fds leaked to child processes
- X-seq: zsh-workers 41554
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: fd used for saving redirected fds leaked to child processes
- Date: Tue, 15 Aug 2017 19:42:13 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1502822533; bh=9sEI6LJ+aDcbwbmU8+OQJfJoHEqwBo/a/u6ogTcmiwc=; h=Date:From:To:Subject:In-Reply-To:References; b=cf+xqBQ6AJVWTl0s7D7v4whbYx4j2vqfGOasYpAmZFRdnWYCEobnd/B94WcRPquTx UqEMgUTDjKFE7HcQ/aHgheq38/otI3BOCQ9drGTVrxoVxS2vhmVVneju0k9Wh1d4zN cpj1z9mAVrHvA4UKccUZXH1SQLSSudXAacEzpODUg4d7VIeIBoGqbD5oBFo02H2vfw Op5UebAVpZqaViE7KDryKBD2drfEzuo/N9QwPskb4yhI1xPTJ+Ng+39hoGrfghjMyM PoNVQexpzp4lX3JlDKOa5EXBAon9K3orgk12DJX4V6WNtI+P85ttiLzLMc+WPKSXxi v4dCxrZ4TUeyA==
- In-reply-to: <CAH+w=7bUMdLYFd0aBE=xFCizZvkK6Msj93fOAFanF5vZO7QsKg@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20170813161207.GA6530@chaz.gmail.com> <20170813194939.7a96bc4b@ntlworld.com> <CGME20170813214600epcas4p4764cb5399e27ff0e52a1936ecdf49346@epcas4p4.samsung.com> <CAH+w=7Y3OaN0JJOo=jG-G+yRZ9NUqbNCGZBw6b452_nOWUAKMA@mail.gmail.com> <20170814100956.363c7ea8@pwslap01u.europe.root.pri> <CAH+w=7bUMdLYFd0aBE=xFCizZvkK6Msj93fOAFanF5vZO7QsKg@mail.gmail.com>
I'm not sure what happened to this.
pws
diff --git a/Src/exec.c b/Src/exec.c
index f339dd6..9996dff 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -972,7 +972,7 @@ enum {
static void
entersubsh(int flags)
{
- int sig, monitor, job_control_ok;
+ int i, sig, monitor, job_control_ok;
if (!(flags & ESUB_KEEPTRAP))
for (sig = 0; sig < SIGCOUNT; sig++)
@@ -1083,6 +1083,14 @@ entersubsh(int flags)
opts[MONITOR] = 0;
opts[USEZLE] = 0;
zleactive = 0;
+ /*
+ * If we've saved fd's for later restoring, we're never going
+ * to restore them now, so just close them.
+ */
+ for (i = 10; i <= max_zsh_fd; i++) {
+ if (fdtable[i] & FDT_SAVED_MASK)
+ zclose(i);
+ }
if (flags & ESUB_PGRP)
clearjobtab(monitor);
get_usage();
@@ -2318,6 +2326,9 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag,
return;
}
save[fd1] = fdN;
+ DPUTS(fdtable[fdN] != FDT_INTERNAL,
+ "Saved file descriptor not marked as internal");
+ fdtable[fdN] |= FDT_SAVED_MASK;
}
}
}
@@ -3575,7 +3586,8 @@ execcmd_exec(Estate state, Execcmd_params eparams,
}
if (!bad && fn->fd1 <= max_zsh_fd) {
if (fn->fd1 >= 10 &&
- fdtable[fn->fd1] == FDT_INTERNAL)
+ (fdtable[fn->fd1] & FDT_TYPE_MASK) ==
+ FDT_INTERNAL)
bad = 3;
}
}
@@ -4270,7 +4282,7 @@ closem(int how)
for (i = 10; i <= max_zsh_fd; i++)
if (fdtable[i] != FDT_UNUSED &&
- (how == FDT_UNUSED || fdtable[i] == how)) {
+ (how == FDT_UNUSED || (fdtable[i] & FDT_TYPE_MASK) == how)) {
if (i == SHTTY)
SHTTY = -1;
zclose(i);
diff --git a/Src/zsh.h b/Src/zsh.h
index ccd11db..91e8d7f 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -456,6 +456,18 @@ enum {
#define FDT_PROC_SUBST 7
#endif
+/*
+ * Mask to get the basic FDT type.
+ */
+#define FDT_TYPE_MASK 15
+
+/*
+ * Bit flag that fd is saved for later restoration.
+ * Currently this is only use with FDT_INTERNAL. We use this fact so as
+ * not to have to mask checks against other types.
+ */
+#define FDT_SAVED_MASK 16
+
/* Flags for input stack */
#define INP_FREE (1<<0) /* current buffer can be free'd */
#define INP_ALIAS (1<<1) /* expanding alias or history */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author