about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2015-05-20 10:14:04 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2015-05-20 10:14:04 -0700
commitaf957f2ed6287f66953742fbca69188cecb98fbf (patch)
tree91a76df0f653461e67056c960f4b3a17e2c03f74
parent9584c76fb74427d76b103d7dda69a4688287d753 (diff)
downloadzsh-af957f2ed6287f66953742fbca69188cecb98fbf.tar.gz
zsh-af957f2ed6287f66953742fbca69188cecb98fbf.tar.xz
zsh-af957f2ed6287f66953742fbca69188cecb98fbf.zip
35231: make mkevnstr() safe for NULL value
-rw-r--r--ChangeLog4
-rw-r--r--Src/params.c14
2 files changed, 13 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 0bdeeaeb3..b1b96379c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,10 @@
 	* Ismail: 35232: Completion/Unix/Type/_urls: matching
 	parentheses.
 
+2015-05-20  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* 35231: Src/params.c: make mkevnstr() safe for NULL value
+
 2015-05-19  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
 	* 35224: Completion/Unix/Command/_git: completion: git: Add
diff --git a/Src/params.c b/Src/params.c
index 045ac1e34..98541a6da 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -4580,17 +4580,21 @@ addenv(Param pm, char *value)
 static char *
 mkenvstr(char *name, char *value, int flags)
 {
-    char *str, *s;
-    int len_name, len_value;
+    char *str, *s = value;
+    int len_name, len_value = 0;
 
     len_name = strlen(name);
-    for (len_value = 0, s = value;
-	 *s && (*s++ != Meta || *s++ != 32); len_value++);
+    if (s)
+	while (*s && (*s++ != Meta || *s++ != 32))
+	    len_value++;
     s = str = (char *) zalloc(len_name + len_value + 2);
     strcpy(s, name);
     s += len_name;
     *s = '=';
-    copyenvstr(s, value, flags);
+    if (value)
+	copyenvstr(s, value, flags);
+    else
+	*++s = '\0';
     return str;
 }