zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: fd used for saving redirected fds leaked to child processes
Date: Fri, 29 Sep 2017 16:18:15 +0100	[thread overview]
Message-ID: <20170929161815.5b2fc24d@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <1506697584.2841623.1122584064.35F87888@webmail.messagingengine.com>

On Fri, 29 Sep 2017 15:06:24 +0000
Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> % Src/zsh -fc ': 3>&1' 
> 1: Src/exec.c:2330: Saved file descriptor not marked as internal

That happens if the file descriptor was already closed, in which case
the new code is inapplicable, so this would access off the start
of the array.

pws

diff --git a/Src/exec.c b/Src/exec.c
index 0d2dc4e..f2e187a 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;
 		}
 	    }
 	}


  reply	other threads:[~2017-09-29 15:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-13 16:12 Stephane Chazelas
2017-08-13 18:49 ` Bart Schaefer
2017-08-13 18:49 ` Peter Stephenson
2017-08-13 21:45   ` Bart Schaefer
2017-08-14  9:09     ` Peter Stephenson
2017-08-14 14:49       ` Bart Schaefer
2017-08-14 15:24         ` Peter Stephenson
2017-08-14 15:31           ` Bart Schaefer
2017-08-14 19:19         ` Peter Stephenson
2017-09-29 15:06           ` Daniel Shahaf
2017-09-29 15:18             ` Peter Stephenson [this message]
2017-08-15 18:42         ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170929161815.5b2fc24d@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).