about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-01-10 18:53:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-01-10 18:53:49 +0000
commitb24d545294507a5af5a63880282247042d934c9e (patch)
tree5ac137d80b21f2381cff5eba0dbdb325ae9aa444 /Src
parented5c4c8e53fce85c1f450c6493b888e4dc223dcf (diff)
downloadzsh-b24d545294507a5af5a63880282247042d934c9e.tar.gz
zsh-b24d545294507a5af5a63880282247042d934c9e.tar.xz
zsh-b24d545294507a5af5a63880282247042d934c9e.zip
users/12412: check for extra arguments in test and [
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c9
-rw-r--r--Src/parse.c6
2 files changed, 13 insertions, 2 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 8ded1c131..299ad3758 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5472,7 +5472,7 @@ zread(int izle, int *readchar)
 
 /* holds arguments for testlex() */
 /**/
-char **testargs;
+char **testargs, **curtestarg;
 
 /* test, [: the old-style general purpose logical expression builtin */
 
@@ -5483,7 +5483,7 @@ testlex(void)
     if (tok == LEXERR)
 	return;
 
-    tokstr = *testargs;
+    tokstr = *(curtestarg = testargs);
     if (!*testargs) {
 	/* if tok is already zero, reading past the end:  error */
 	tok = tok ? NULLTOK : LEXERR;
@@ -5557,6 +5557,11 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func)
 	return 1;
     }
 
+    if (*curtestarg) {
+	zwarnnam(name, "too many arguments");
+	return 1;
+    }
+
     /* syntax is OK, so evaluate */
 
     state.prog = prog;
diff --git a/Src/parse.c b/Src/parse.c
index 30f3abe50..af3cba9d3 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -537,6 +537,12 @@ parse_list(void)
     return bld_eprog();
 }
 
+/*
+ * This entry point is only used for bin_test, our attempt to
+ * provide compatibility with /bin/[ and /bin/test.  Hence
+ * at this point condlex should always be set to testlex.
+ */
+
 /**/
 mod_export Eprog
 parse_cond(void)