about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2011-12-03 23:15:37 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2011-12-03 23:15:37 +0000
commit74eed99c312de05e19b54ba6b5d37a0aeb4ba713 (patch)
treef30c88f86868eaecc78a917f105fb99be507cc3b
parent724fd07a67f135c74eba57e9f25fd342201ec722 (diff)
downloadzsh-74eed99c312de05e19b54ba6b5d37a0aeb4ba713.tar.gz
zsh-74eed99c312de05e19b54ba6b5d37a0aeb4ba713.tar.xz
zsh-74eed99c312de05e19b54ba6b5d37a0aeb4ba713.zip
29940: metafy() added null termination even if buffer was not modifiable
-rw-r--r--ChangeLog5
-rw-r--r--Src/utils.c4
2 files changed, 6 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b61f903bb..324da711c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2011-12-03  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
+	* 29940: Src/utils.c (metafy): null termination shouldn't
+	be applied to original buffer if not to be modified.
+
 	* From Stef VAN VLIERBERGHE: 29934: Src/lex.c (add): use of
 	uninitialised memoryx when lexer needed to reallocate token.
 
@@ -15650,5 +15653,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5514 $
+* $Revision: 1.5515 $
 *****************************************************
diff --git a/Src/utils.c b/Src/utils.c
index 6c2ea98d5..014cb2fa2 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3959,7 +3959,7 @@ metafy(char *buf, int len, int heap)
 	    if (imeta(*e++))
 		meta++;
 
-    if (meta || heap == META_DUP || heap == META_HEAPDUP) {
+    if (meta || heap == META_DUP || heap == META_HEAPDUP || *e != '\0') {
 	switch (heap) {
 	case META_REALLOC:
 	    buf = zrealloc(buf, len + meta + 1);
@@ -4002,8 +4002,8 @@ metafy(char *buf, int len, int heap)
 		meta--;
 	    }
 	}
+	*e = '\0';
     }
-    *e = '\0';
     return buf;
 }