Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: 'cd' built-in crashed zsh on a broken file system
On Tue, 20 Jan 2015 10:28:10 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Jan 20, 1:35pm, Kamil Dudka wrote:
> } Subject: 'cd' built-in crashed zsh on a broken file system
> }
> } It is not clear to me why pwd was NULL after the return from cd_new_pwd()
>
> xsymlink() in utils.c:
>
> if (*s != '/')
> return NULL;
>
> called from findpwd() also utils.c, which in turn is only called if you
> have CHASE_LINKS set.
>
> I'm not sure if the right thing to do is test the return of xsymlink()
> down in findpwd(), or to check the return of findpwd() in cd_new_pwd().
I'd say the latter: dealing with an I'm-sorry-dave-I-can't-do-that is a
bit neater higher up otherwise the intermediate return values are in
some sort of limbo.
I don't think there's any point in printing an error message: we don't
know what happened, so just pretend it didn't.
How about this?
diff --git a/Src/builtin.c b/Src/builtin.c
index 1818941..08be1ac 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 4561b5e..cf18f12 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 */
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author