Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: bug with $PWD in /



On Sep 19,  8:28pm, Stephane Chazelas wrote:
} Subject: Re: bug with $PWD in /
}
} So, the should recompute $PWD if the one it gets from the
} environment is a relative path (it's not only about . or ..,
} think of symlinks).

It'd have to be a symlink from the current directory to itself, tho.
Other symbolic links are explicitly permitted by the text you quoted.

This replaces the previous patch, although it's 90% the same.

diff --git a/Src/utils.c b/Src/utils.c
index 1de3d95..ab3b0c2 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -692,9 +692,23 @@ ispwd(char *s)
 {
     struct stat sbuf, tbuf;
 
-    if (stat(unmeta(s), &sbuf) == 0 && stat(".", &tbuf) == 0)
-	if (sbuf.st_dev == tbuf.st_dev && sbuf.st_ino == tbuf.st_ino)
-	    return 1;
+    /* POSIX: environment PWD must be absolute */
+    if (*s != '/')
+	return 0;
+
+    if (stat((s = unmeta(s)), &sbuf) == 0 && stat(".", &tbuf) == 0)
+	if (sbuf.st_dev == tbuf.st_dev && sbuf.st_ino == tbuf.st_ino) {
+	    /* POSIX: No element of $PWD may be "." or ".." */
+	    while (*s) {
+		if (s[0] == '.' &&
+		    (!s[1] || s[1] == '/' ||
+		     (s[1] == '.' && (!s[2] || s[2] == '/'))))
+		    break;
+		while (*s++ != '/' && *s)
+		    continue;
+	    }
+	    return !*s;
+	}
     return 0;
 }
 



Messages sorted by: Reverse Date, Date, Thread, Author