Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: latest from CVS segfaults when FD ulimit is set too low
- X-seq: zsh-workers 27283
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: latest from CVS segfaults when FD ulimit is set too low
- Date: Mon, 21 Sep 2009 21:45:28 +0100
- In-reply-to: <87iqfgwplu.fsf@xxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <87iqfgwplu.fsf@xxxxxxxxxxxx>
On Fri, 18 Sep 2009 11:48:13 +0200
Jim Meyering <jim@xxxxxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author