Blob Blame History Raw
From 3427fe59c2d76ddbf4b23908c6ae5272734c7c8b Mon Sep 17 00:00:00 2001
From: "Barton E. Schaefer" <schaefer@zsh.org>
Date: Wed, 20 May 2015 10:14:04 -0700
Subject: [PATCH] 35231: make mkevnstr() safe for NULL value

Upstream-commit: af957f2ed6287f66953742fbca69188cecb98fbf
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Src/params.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/Src/params.c b/Src/params.c
index 61edc5d..d0ce0a9 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -4534,17 +4534,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;
 }
 
-- 
2.4.1