From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22391 invoked from network); 21 Sep 2009 20:46:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from new-brage.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.254.104) by ns1.primenet.com.au with SMTP; 21 Sep 2009 20:46:01 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 47125 invoked from network); 21 Sep 2009 20:45:55 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Sep 2009 20:45:55 -0000 Received: (qmail 25790 invoked by alias); 21 Sep 2009 20:45:52 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 27283 Received: (qmail 25771 invoked from network); 21 Sep 2009 20:45:52 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 21 Sep 2009 20:45:52 -0000 Received: from mtaout02-winn.ispmail.ntl.com (mtaout02-winn.ispmail.ntl.com [81.103.221.48]) by bifrost.dotsrc.org (Postfix) with ESMTP id DA2CE804CE03 for ; Mon, 21 Sep 2009 22:45:45 +0200 (CEST) Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20090921204544.LQST6611.mtaout02-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com> for ; Mon, 21 Sep 2009 21:45:44 +0100 Received: from pws-pc ([82.6.98.90]) by aamtaout04-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20090921204544.EYCR22934.aamtaout04-winn.ispmail.ntl.com@pws-pc> for ; Mon, 21 Sep 2009 21:45:44 +0100 Date: Mon, 21 Sep 2009 21:45:28 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: latest from CVS segfaults when FD ulimit is set too low Message-ID: <20090921214528.7c7b412c@pws-pc> In-Reply-To: <87iqfgwplu.fsf@meyering.net> References: <87iqfgwplu.fsf@meyering.net> X-Mailer: Claws Mail 3.7.2 (GTK+ 2.16.6; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.0 c=1 a=VR7FTlIkdzgA:10 a=O0v0mdFJAAAA:8 a=NLZqzBF-AAAA:8 a=1a174MgrtQMtb6brGOAA:9 a=fJQ0dqc8ffSV3Ru1NhUA:7 a=O-dJFcQSdsDN0HoTJh2q2hrHcPEA:4 a=VvQ7Xpx9qTgA:10 a=_dQi-Dcv4p4A:10 X-Virus-Scanned: ClamAV 0.94.2/9820/Mon Sep 21 18:39:04 2009 on bifrost X-Virus-Status: Clean On Fri, 18 Sep 2009 11:48:13 +0200 Jim Meyering wrote: > $ printf '_src_etc_profile_d() { f=; }\n_src_etc_profile_d\n' > k > $ Src/zsh -f -c '( . ./k; ulimit -n 7 && exec 0 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/