Blob Blame History Raw
From e4761e2cc86db577127ed7f6884bd42363883a16 Mon Sep 17 00:00:00 2001
From: Peter Stephenson <pws@users.sourceforge.net>
Date: Tue, 22 Jan 2013 16:28:58 +0000
Subject: [PATCH 1/3] 30993: fix parameter modifier crash with :wq on empty
 string

Upstream-commit: 44757a653cb547ae7b556e8c92629d296d3c1f12
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Src/subst.c            | 10 +++++++++-
 Test/D04parameter.ztst |  7 +++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Src/subst.c b/Src/subst.c
index 974a845..a4df256 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3707,6 +3707,11 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags)
 	char *y;
 
 	x = val;
+	if (!x) {
+	    /* Shouldn't have got here with a NULL string. */
+	    DPUTS(1, "value is NULL in paramsubst");
+	    return NULL;
+	}
 	if (prenum || postnum)
 	    x = dopadding(x, prenum, postnum, preone, postone,
 			  premul, postmul
@@ -4021,7 +4026,10 @@ modify(char **str, char **ptr)
 		    all = tmp;
 		    t = e;
 		}
-		*str = all;
+		if (!all)
+		    *str = dupstring("");
+		else
+		    *str = all;
 
 	    } else {
 		switch (c) {
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 01f8412..bea9459 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -1544,3 +1544,10 @@
 0:Regression test for shwordsplit with null or unset IFS and quoted array
 >abc
 >a b c
+
+   foo=
+   print ${foo:wq}
+   print ${:wq}
+0:Empty parameter shouldn't cause modifiers to crash the shell
+>
+>
-- 
2.5.2


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 2/3] 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
@@ -4488,17 +4488,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


From e92e9cbe55c7611e6eef59bf671de9bc95225d56 Mon Sep 17 00:00:00 2001
From: Peter Stephenson <pws@zsh.org>
Date: Tue, 6 Oct 2015 09:28:07 +0100
Subject: [PATCH 3/3] 36780: Fix crash in ksh mode with -n and $HOME.

If home variable is NULL ensure HOME is unset.

Upstream-commit: 83a175795a444e8169fcb592a110d4d15a09b907
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Src/params.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/Src/params.c b/Src/params.c
index e9e6545..babf6f2 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -755,17 +755,18 @@ createparamtable(void)
 #endif
     opts[ALLEXPORT] = oae;
 
+    /*
+     * For native emulation we always set the variable home
+     * (see setupvals()).
+     */
+    pm = (Param) paramtab->getnode(paramtab, "HOME");
     if (EMULATION(EMULATE_ZSH))
     {
-	/*
-	 * For native emulation we always set the variable home
-	 * (see setupvals()).
-	 */
-	pm = (Param) paramtab->getnode(paramtab, "HOME");
 	pm->node.flags &= ~PM_UNSET;
 	if (!(pm->node.flags & PM_EXPORTED))
 	    addenv(pm, home);
-    }
+    } else if (!home)
+	pm->node.flags |= PM_UNSET;
     pm = (Param) paramtab->getnode(paramtab, "LOGNAME");
     if (!(pm->node.flags & PM_EXPORTED))
 	addenv(pm, pm->u.str);
-- 
2.5.2