about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-04-15 10:40:01 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-04-15 10:40:01 +0000
commitd6089cc8b17ed7d33850bb9075a9c6771fe120d6 (patch)
treea784b891867af1aef0e10b19fca30d066dc61f84 /Src/exec.c
parentc69b149cb5ce6446eb267074f640e34ca726a45d (diff)
downloadzsh-d6089cc8b17ed7d33850bb9075a9c6771fe120d6.tar.gz
zsh-d6089cc8b17ed7d33850bb9075a9c6771fe120d6.tar.xz
zsh-d6089cc8b17ed7d33850bb9075a9c6771fe120d6.zip
21143: more care about special file descriptors
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 1ac3f50fd..f5feba50b 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -77,7 +77,7 @@ long lastval2;
  * by zclose.                                                      */
 
 /**/
-unsigned char *fdtable;
+mod_export unsigned char *fdtable;
 
 /* The allocated size of fdtable */
 
@@ -87,7 +87,7 @@ int fdtable_size;
 /* The highest fd that marked with nonzero in fdtable */
 
 /**/
-int max_zsh_fd;
+mod_export int max_zsh_fd;
 
 /* input fd from the coprocess */
 
@@ -2360,13 +2360,22 @@ execcmd(Estate state, int input, int output, int how, int last1)
 			bad = 2;
 		    } else {
 			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) {
-			zwarn(bad == 2 ?
-			      "can't close file descriptor from readonly parameter" :
-			      "parameter %s does not contain a file descriptor",
-			      fn->varid, 0);
+			const char *bad_msg[] = {
+			    "parameter %s does not contain a file descriptor",
+			    "can't close file descriptor from readonly parameter %s",
+			    "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();
 		    }
 		}