zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk
Subject: Re: latest from CVS segfaults when FD ulimit is set too low
Date: Mon, 21 Sep 2009 21:45:28 +0100	[thread overview]
Message-ID: <20090921214528.7c7b412c@pws-pc> (raw)
In-Reply-To: <87iqfgwplu.fsf@meyering.net>

On Fri, 18 Sep 2009 11:48:13 +0200
Jim Meyering <jim@meyering.net> wrote:
>   $ printf '_src_etc_profile_d() { f=; }\n_src_etc_profile_d\n' > k
>   $ Src/zsh -f -c '( . ./k; ulimit -n 7 && exec 0</dev/null )'
>   zsh:1: cannot duplicate fd 0: invalid argument
>   zsh: segmentation fault  Src/zsh -f ...

This fixes the segmentation fault:  it was intermittent because we were
accessing uninitialised memory, so this is a fully paid up bug
regardless of file descriptor limitations.

I haven't looked further: this sort of stuff is certainly not well
tested and there could well be more nasties.  If you can provide any
further code to exercise it, splendid.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.170
diff -u -r1.170 exec.c
--- Src/exec.c	12 Jul 2009 15:10:07 -0000	1.170
+++ Src/exec.c	21 Sep 2009 20:41:49 -0000
@@ -1980,6 +1980,7 @@
 		     */
 		    if (fdN < 0 && errno != EBADF) {
 			zerr("cannot duplicate fd %d: %e", fd1, errno);
+			mfds[fd1] = NULL;
 			closemnodes(mfds);
 			return;
 		    }
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.229
diff -u -r1.229 utils.c
--- Src/utils.c	9 Jul 2009 20:20:53 -0000	1.229
+++ Src/utils.c	21 Sep 2009 20:41:49 -0000
@@ -1631,7 +1631,8 @@
 #else
 	int fe = movefd(dup(fd));
 #endif
-	zclose(fd);
+	if (fe != -1)
+	    zclose(fd);
 	fd = fe;
     }
     if(fd != -1) {

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2009-09-21 20:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18  9:48 Jim Meyering
2009-09-21 20:45 ` Peter Stephenson [this message]
2009-09-22  9:00   ` Peter Stephenson
2009-09-22 13:40     ` Bart Schaefer
2009-09-23 19:40       ` Peter Stephenson
2009-09-22 15:35     ` Wayne Davison
2009-09-22 15:39       ` 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=20090921214528.7c7b412c@pws-pc \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@sunsite.dk \
    /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).