summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-06-13 15:41:00 +0100
committerPeter Stephenson <pws@zsh.org>2017-06-13 15:41:00 +0100
commiteb783754bdb74377f3cea4ceca9c23a02ea1bf58 (patch)
tree3e0a35c59c8f624d06e979edba8f2aa364bb3aea /Src
parentd5c22d356ba442fd5811e15cc35b5480008722f4 (diff)
downloadzsh-eb783754bdb74377f3cea4ceca9c23a02ea1bf58.tar.gz
zsh-eb783754bdb74377f3cea4ceca9c23a02ea1bf58.tar.xz
zsh-eb783754bdb74377f3cea4ceca9c23a02ea1bf58.zip
41284: Fix NULL dereference in cd.
This happened in sh compatiblity mode if HOME was not set
and cd was used with no argument.
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 0b3949437..2e72ba20a 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -880,8 +880,13 @@ cd_get_dest(char *nam, char **argv, int hard, int func)
 	    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;
@@ -936,6 +941,10 @@ cd_get_dest(char *nam, char **argv, int hard, int func)
     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));