Blob Blame History Raw
From 19c75aec6843b827fa7ef3f39174090ee7f8ac18 Mon Sep 17 00:00:00 2001
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
Date: Thu, 22 Jan 2015 20:20:15 +0000
Subject: [PATCH 1/2] 34331: better handling of NULL in cd.

Problem was return from symbolic link expander in weird cases
where there file system isn't behaving itself properly.

Upstream-commit: 12b813b5895cae579e403dafe43878868f27fe0f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Src/builtin.c |  8 +++++---
 Src/utils.c   | 11 +++++++----
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index 2118835..489ca23 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 e6eb8e6..80396a2 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1049,10 +1049,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 */
-- 
2.1.0


From d0777e66d47d0a87f3171962d8137a6cb75d7ade Mon Sep 17 00:00:00 2001
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
Date: Sun, 25 Jan 2015 18:03:20 +0000
Subject: [PATCH 2/2] 34383: ztrdup() should be dupstring() in new cd code

Upstream-commit: ccd3663d4e9a1749450b35cc689359f78a310c04
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Src/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Src/utils.c b/Src/utils.c
index 80396a2..ef71210 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1055,7 +1055,7 @@ getnameddir(char *name)
 		zsfree(dir);
 		return str;
 	    } else
-		return ztrdup(pw->pw_dir);
+		return dupstring(pw->pw_dir);
 	}
     }
 #endif /* HAVE_GETPWNAM */
-- 
2.1.0