about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJulien Cretin <zsh@ia0.eu>2016-10-06 11:36:32 +0200
committerPeter Stephenson <pws@zsh.org>2016-10-06 10:57:10 +0100
commita96e34b459d55240b0f4af37ac73aca916720883 (patch)
tree73760ff8aa8fa98108778f88fb71425cd1c52472
parentffa6c76253b9833379893e87e8504eb03b4e954e (diff)
downloadzsh-a96e34b459d55240b0f4af37ac73aca916720883.tar.gz
zsh-a96e34b459d55240b0f4af37ac73aca916720883.tar.xz
zsh-a96e34b459d55240b0f4af37ac73aca916720883.zip
39579: Fix string calculation for parameter quoting.
Where there was no closing quote the size or position of the null
could be wrongly calculated.
-rw-r--r--ChangeLog4
-rw-r--r--Src/subst.c6
2 files changed, 7 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e3e276e00..aec3a20aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2016-10-06  Peter Stephenson  <p.stephenson@samsung.com>
 
+	* Julien Cretin: 39579: Src/subst.c: position of \0
+	with optional quoting in parameter substitution was wrongly
+	calculated.
+
 	* 39578: Test/C03traps.ztst: Test some more ERR_RETURN cases
 	involving "&&" and functions.
 
diff --git a/Src/subst.c b/Src/subst.c
index ecd74879f..447177409 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3629,7 +3629,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 			if (pre)
 			    ap[0][pre - 1] = ap[0][pre + sl] =
 				(quotetype != QT_DOUBLE ? '\'' : '"');
-			ap[0][pre + sl + 1] = '\0';
+			ap[0][pre + sl + post] = '\0';
 			if (quotetype == QT_DOLLARS)
 			  ap[0][0] = '$';
 		    }
@@ -3667,12 +3667,12 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		    char *tmp;
 		    tmp = quotestring(val, quotetype);
 		    sl = strlen(tmp);
-		    val = (char *) zhalloc(pre + sl + 2);
+		    val = (char *) zhalloc(pre + sl + post + 1);
 		    strcpy(val + pre, tmp);
 		    if (pre)
 			val[pre - 1] = val[pre + sl] =
 			    (quotetype != QT_DOUBLE ? '\'' : '"');
-		    val[pre + sl + 1] = '\0';
+		    val[pre + sl + post] = '\0';
 		    if (quotetype == QT_DOLLARS)
 		      val[0] = '$';
 		} else