1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-08-21 06:11:09 +02:00

21143: more care about special file descriptors

This commit is contained in:
Peter Stephenson 2005-04-15 10:40:01 +00:00
parent c69b149cb5
commit d6089cc8b1
3 changed files with 26 additions and 7 deletions

View file

@ -1,3 +1,8 @@
2005-04-15 Peter Stephenson <pws@csr.com>
* 21143: Src/exec.c, Src/Modules/socket.c: be more careful when
closing or opening sockets onto file descriptors.
2005-04-14 Peter Stephenson <pws@csr.com> 2005-04-14 Peter Stephenson <pws@csr.com>
* 21141: Doc/Zsh/redirect.yo, Src/exec.c, Test/A04redirect.ztst: * 21141: Doc/Zsh/redirect.yo, Src/exec.c, Test/A04redirect.ztst:

View file

@ -78,6 +78,11 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func))
OPT_ARG(ops, 'd'), 0); OPT_ARG(ops, 'd'), 0);
return 1; return 1;
} }
if (targetfd <= max_zsh_fd && fdtable[targetfd] != FDT_UNUSED) {
zwarnnam(nam, "file descriptor %d is in use by the shell",
NULL, targetfd);
return 1;
}
} }
if (OPT_ISSET(ops,'l')) { if (OPT_ISSET(ops,'l')) {

View file

@ -77,7 +77,7 @@ long lastval2;
* by zclose. */ * by zclose. */
/**/ /**/
unsigned char *fdtable; mod_export unsigned char *fdtable;
/* The allocated size of fdtable */ /* The allocated size of fdtable */
@ -87,7 +87,7 @@ int fdtable_size;
/* The highest fd that marked with nonzero in fdtable */ /* The highest fd that marked with nonzero in fdtable */
/**/ /**/
int max_zsh_fd; mod_export int max_zsh_fd;
/* input fd from the coprocess */ /* input fd from the coprocess */
@ -2360,13 +2360,22 @@ execcmd(Estate state, int input, int output, int how, int last1)
bad = 2; bad = 2;
} else { } else {
fn->fd1 = (int)getintvalue(v); fn->fd1 = (int)getintvalue(v);
bad = errflag; if (errflag)
bad = 1;
else if (fn->fd1 > max_zsh_fd)
bad = 3;
else if (fn->fd1 >= 10 &&
fdtable[fn->fd1] == FDT_INTERNAL)
bad = 4;
} }
if (bad) { if (bad) {
zwarn(bad == 2 ? const char *bad_msg[] = {
"can't close file descriptor from readonly parameter" : "parameter %s does not contain a file descriptor",
"parameter %s does not contain a file descriptor", "can't close file descriptor from readonly parameter %s",
fn->varid, 0); "file descriptor %d out of range, not closed",
"file descriptor %d used by shell, not closed"
};
zwarn(bad_msg[bad-1], fn->varid, fn->fd1);
execerr(); execerr();
} }
} }