summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-04-03 10:03:13 +0100
committerPeter Stephenson <pws@zsh.org>2017-04-03 10:04:03 +0100
commitf6ab9a281dde719e180809db52d0d142d0c0a240 (patch)
tree905c26346e1137c14f6535739aad608aa81131d3 /Src
parent207263a61e54a413d02c52f08d7771dd082d20f1 (diff)
downloadzsh-f6ab9a281dde719e180809db52d0d142d0c0a240.tar.gz
zsh-f6ab9a281dde719e180809db52d0d142d0c0a240.tar.xz
zsh-f6ab9a281dde719e180809db52d0d142d0c0a240.zip
40932: Parameter subscripts need to count parentheses.
Otherwise they can terminate in the middle of an expression.
Diffstat (limited to 'Src')
-rw-r--r--Src/params.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Src/params.c b/Src/params.c
index 785b9ead7..a9683a6f6 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1183,7 +1183,7 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
        int *prevcharlen, int *nextcharlen)
 {
     int hasbeg = 0, word = 0, rev = 0, ind = 0, down = 0, l, i, ishash;
-    int keymatch = 0, needtok = 0, arglen, len;
+    int keymatch = 0, needtok = 0, arglen, len, inpar = 0;
     char *s = *str, *sep = NULL, *t, sav, *d, **ta, **p, *tt, c;
     zlong num = 1, beg = 0, r = 0, quote_arg = 0;
     Patprog pprog = NULL;
@@ -1322,8 +1322,9 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
     }
 
     for (t = s, i = 0;
-	 (c = *t) && ((c != Outbrack &&
-		       (ishash || c != ',')) || i); t++) {
+	 (c = *t) &&
+	     ((c != Outbrack && (ishash || c != ',')) || i || inpar);
+	 t++) {
 	/* Untokenize inull() except before brackets and double-quotes */
 	if (inull(c)) {
 	    c = t[1];
@@ -1344,6 +1345,10 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
 	    i++;
 	else if (c == ']' || c == Outbrack)
 	    i--;
+	if (c == '(' || c == Inpar)
+	    inpar++;
+	else if (c == ')' || c == Outpar)
+	    inpar--;
 	if (ispecial(c))
 	    needtok = 1;
     }