about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorFrank Terbeck <bewater@users.sourceforge.net>2012-01-16 22:14:11 +0000
committerFrank Terbeck <bewater@users.sourceforge.net>2012-01-16 22:14:11 +0000
commitc8381cda78016f61e1a30cc34f1fb996300a0d41 (patch)
tree30cb033db7a440b82a2630a64faa74cdfac82c73 /Src/exec.c
parent737a87654f6bb4f26890add0cb5b6aa7653244d5 (diff)
downloadzsh-c8381cda78016f61e1a30cc34f1fb996300a0d41.tar.gz
zsh-c8381cda78016f61e1a30cc34f1fb996300a0d41.tar.xz
zsh-c8381cda78016f61e1a30cc34f1fb996300a0d41.zip
30111: Src/exec.c: Fix segfaults with exec options.
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 9b3c50372..44fcbdd9f 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2487,6 +2487,11 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		 * with the zsh style.
 		 */
 		while (next && *next == '-' && strlen(next) >= 2) {
+		    if (!firstnode(args)) {
+			zerr("exec requires a command to execute");
+			errflag = lastval = 1;
+			return;
+		    }
 		    uremnode(args, firstnode(args));
 		    if (!strcmp(next, "--"))
 			break;
@@ -2499,6 +2504,11 @@ execcmd(Estate state, int input, int output, int how, int last1)
 				/* position on last non-NULL character */
 				cmdopt += strlen(cmdopt+1);
 			    } else {
+				if (!firstnode(args)) {
+				    zerr("exec requires a command to execute");
+				    errflag = lastval = 1;
+				    return;
+				}
 				if (!nextnode(firstnode(args))) {
 				    zerr("exec flag -a requires a parameter");
 				    errflag = lastval = 1;
@@ -2521,7 +2531,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
 			    return;
 			}
 		    }
-		    next = (char *) getdata(nextnode(firstnode(args)));
+		    if (firstnode(args) && nextnode(firstnode(args)))
+			next = (char *) getdata(nextnode(firstnode(args)));
 		}
 		if (exec_argv0) {
 		    char *str, *s;