From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4981 invoked from network); 10 Oct 1999 14:36:03 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 10 Oct 1999 14:36:03 -0000 Received: (qmail 10160 invoked by alias); 10 Oct 1999 14:35:51 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8187 Received: (qmail 10153 invoked from network); 10 Oct 1999 14:35:51 -0000 Subject: PATCH: no more fd mixups To: zsh-workers@sunsite.auc.dk Date: Sun, 10 Oct 1999 15:35:49 +0100 (BST) X-Mailer: ELM [version 2.4ME+ PL48 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: From: Zefram This patch prevents the user from duping the shell's private file descriptors (deemed to be fds 10 and above). I had to do a slight hack to allow the coprocess file descriptors to be duped, but the extra logic for that incidentally made it easy to improve the error message for "<&p" where there is no coprocess. -zefram diff -cr ../zsh-/Src/exec.c Src/exec.c *** ../zsh-/Src/exec.c Sun Oct 10 14:38:24 1999 --- Src/exec.c Sun Oct 10 15:21:05 1999 *************** *** 1907,1920 **** case MERGEOUT: if(fn->fd2 < 10) closemn(mfds, fn->fd2); ! fil = dup(fn->fd2); if (fil == -1) { char fdstr[4]; closemnodes(mfds); fixfds(save); ! sprintf(fdstr, "%d", fn->fd2); ! zerr("%s: %e", fdstr, errno); execerr(); } addfd(forked, save, mfds, fn->fd1, fil, fn->type == MERGEOUT); --- 1907,1929 ---- case MERGEOUT: if(fn->fd2 < 10) closemn(mfds, fn->fd2); ! if(fn->fd2 > 9) { ! fil = -1; ! errno = EBADF; ! } else { ! int fd = fn->fd2; ! if(fd == -2) ! fd = (fn->type == MERGEOUT) ? coprocout : coprocin; ! fil = dup(fd); ! } if (fil == -1) { char fdstr[4]; closemnodes(mfds); fixfds(save); ! if(fn->fd2 != -2) ! sprintf(fdstr, "%d", fn->fd2); ! zerr("%s: %e", fn->fd2 == -2 ? "coprocess" : fdstr, errno); execerr(); } addfd(forked, save, mfds, fn->fd1, fil, fn->type == MERGEOUT); diff -cr ../zsh-/Src/glob.c Src/glob.c *** ../zsh-/Src/glob.c Sun Oct 10 14:38:24 1999 --- Src/glob.c Sun Oct 10 15:21:23 1999 *************** *** 1580,1586 **** if (s[0] == '-' && !s[1]) fn->type = CLOSE; else if (s[0] == 'p' && !s[1]) ! fn->fd2 = (fn->type == MERGEOUT) ? coprocout : coprocin; else { while (idigit(*s)) s++; --- 1580,1586 ---- if (s[0] == '-' && !s[1]) fn->type = CLOSE; else if (s[0] == 'p' && !s[1]) ! fn->fd2 = -2; else { while (idigit(*s)) s++; END