File CVE-2017-18205.patch of Package zsh.7007

commit eb783754bdb74377f3cea4ceca9c23a02ea1bf58
Author: Peter Stephenson <pws@zsh.org>
Date:   Tue Jun 13 15:41:00 2017 +0100

    41284: Fix NULL dereference in cd.
    
    This happened in sh compatiblity mode if HOME was not set
    and cd was used with no argument.

Index: zsh-5.0.5/Src/builtin.c
===================================================================
--- zsh-5.0.5.orig/Src/builtin.c
+++ zsh-5.0.5/Src/builtin.c
@@ -844,8 +844,13 @@ cd_get_dest(char *nam, char **argv, int
 	    dir = nextnode(firstnode(dirstack));
 	if (dir)
 	    zinsertlinknode(dirstack, dir, getlinknode(dirstack));
-	else if (func != BIN_POPD)
+	else if (func != BIN_POPD) {
+	    if (!home) {
+		zwarnnam(nam, "HOME not set");
+		return NULL;
+	    }
 	    zpushnode(dirstack, ztrdup(home));
+	}
     } else if (!argv[1]) {
 	int dd;
 	char *end;
@@ -900,6 +905,10 @@ cd_get_dest(char *nam, char **argv, int
     if (!dir) {
 	dir = firstnode(dirstack);
     }
+    if (!dir || !getdata(dir)) {
+	DPUTS(1, "Directory not set, not detected early enough");
+	return NULL;
+    }
     if (!(dest = cd_do_chdir(nam, getdata(dir), hard))) {
 	if (!target)
 	    zsfree(getlinknode(dirstack));
openSUSE Build Service is sponsored by