From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8118 invoked from network); 10 Oct 1999 16:39:15 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 10 Oct 1999 16:39:15 -0000 Received: (qmail 16613 invoked by alias); 10 Oct 1999 16:39:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8189 Received: (qmail 16606 invoked from network); 10 Oct 1999 16:39:07 -0000 From: "Bart Schaefer" Message-Id: <991010163903.ZM2414@candle.brasslantern.com> Date: Sun, 10 Oct 1999 16:39:02 +0000 In-Reply-To: Comments: In reply to Zefram "PATCH: no more fd mixups" (Oct 10, 3:35pm) References: <991010155440.ZM2271@candle.brasslantern.com> In-Reply-To: <991010155440.ZM2271@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "Re: PATCH: 3.0.6/3.1.6: Re: All sorts of file-descriptor strangeness" (Oct 10, 3:54pm) X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-workers@sunsite.auc.dk Subject: PATCH: Re: PATCH: no more fd mixups MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 10, 3:35pm, Zefram wrote: } Subject: PATCH: no more fd mixups } } This patch prevents the user from duping the shell's private file } descriptors (deemed to be fds 10 and above). On Oct 10, 3:54pm, Bart Schaefer wrote: } Subject: Re: PATCH: 3.0.6/3.1.6: Re: All sorts of file-descriptor strangen } } If we continue to limit the FDs on the LHS to 0-9, then we can simply } report EBADF whenever one of the "private" FDs appears on the RHS. Here's a tweak to Zefram's patch to really limit the descriptors to those in use by the shell. The substantive change is only to throw in the test that the descriptor is in the fdtable[] array, but I took the liberty of changing some old no-space-between-`if'-and-`(' style to the style now in wider use in the zsh code. Index: Src/exec.c =================================================================== RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/exec.c,v retrieving revision 1.62 diff -u -r1.62 exec.c --- exec.c 1999/10/10 16:29:06 1.62 +++ exec.c 1999/10/10 16:29:56 @@ -1906,9 +1906,9 @@ break; case MERGEIN: case MERGEOUT: - if(fn->fd2 < 10) + if (fn->fd2 < 10) closemn(mfds, fn->fd2); - if(fn->fd2 > 9) { + if (fn->fd2 > 9 && fdtable[fn->fd2]) { fil = -1; errno = EBADF; } else { @@ -1922,7 +1922,7 @@ closemnodes(mfds); fixfds(save); - if(fn->fd2 != -2) + if (fn->fd2 != -2) sprintf(fdstr, "%d", fn->fd2); zerr("%s: %e", fn->fd2 == -2 ? "coprocess" : fdstr, errno); execerr(); -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com