From: Zefram <zefram@fysh.org>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: no more fd mixups
Date: Sun, 10 Oct 1999 15:35:49 +0100 (BST) [thread overview]
Message-ID: <E11aK4j-0006RV-00@crucigera.fysh.org> (raw)
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
next reply other threads:[~1999-10-10 14:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-10-10 14:35 Zefram [this message]
-- strict thread matches above, loose matches on Subject: below --
1999-10-05 9:45 All sorts of file-descriptor strangeness Bart Schaefer
1999-10-10 8:27 ` PATCH: 3.0.6/3.1.6: " Bart Schaefer
1999-10-10 13:35 ` Zefram
1999-10-10 15:54 ` Bart Schaefer
1999-10-10 16:39 ` PATCH: Re: PATCH: no more fd mixups Bart Schaefer
1999-10-10 17:53 ` Zefram
1999-10-10 21:11 ` PATCH: 3.0.6/3.1.6: Re: All sorts of file-descriptor strangeness Bart Schaefer
1999-10-11 8:12 ` Zefram
1999-10-10 17:41 ` Zefram
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=E11aK4j-0006RV-00@crucigera.fysh.org \
--to=zefram@fysh.org \
--cc=zsh-workers@sunsite.auc.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).