summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c8
-rw-r--r--Src/utils.c11
2 files changed, 12 insertions, 7 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 1818941b2..08be1acdd 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -1156,9 +1156,11 @@ cd_new_pwd(int func, LinkNode dir, int quiet)
 	zsfree(getlinknode(dirstack));
 
     if (chasinglinks) {
-	s = new_pwd;
-	new_pwd = findpwd(s);
-	zsfree(s);
+	s = findpwd(new_pwd);
+	if (s) {
+	    zsfree(new_pwd);
+	    new_pwd = s;
+	}
     }
     if (isset(PUSHDIGNOREDUPS)) {
 	LinkNode n;
diff --git a/Src/utils.c b/Src/utils.c
index 4561b5e9a..cf18f1240 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1108,10 +1108,13 @@ getnameddir(char *name)
 	if ((pw = getpwnam(name))) {
 	    char *dir = isset(CHASELINKS) ? xsymlink(pw->pw_dir)
 		: ztrdup(pw->pw_dir);
-	    adduserdir(name, dir, ND_USERNAME, 1);
-	    str = dupstring(dir);
-	    zsfree(dir);
-	    return str;
+	    if (dir) {
+		adduserdir(name, dir, ND_USERNAME, 1);
+		str = dupstring(dir);
+		zsfree(dir);
+		return str;
+	    } else
+		return ztrdup(pw->pw_dir);
 	}
     }
 #endif /* HAVE_GETPWNAM */