about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2020-03-21 19:09:04 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2020-03-25 23:49:02 +0000
commit12347c26ce2041e9c06abb0a42d1fa759c4a0551 (patch)
tree7f83166bfb7c71d480edde4da161cb3655d73295 /Src
parentdb8d16a060b76b6382daa4365d2d2ad5902cc735 (diff)
downloadzsh-12347c26ce2041e9c06abb0a42d1fa759c4a0551.tar.gz
zsh-12347c26ce2041e9c06abb0a42d1fa759c4a0551.tar.xz
zsh-12347c26ce2041e9c06abb0a42d1fa759c4a0551.zip
45583/0006: Don't use xsymlinks() in 'whence -s'.
Diffstat (limited to 'Src')
-rw-r--r--Src/utils.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Src/utils.c b/Src/utils.c
index b0f6820fb..df2ab11a6 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -919,7 +919,14 @@ slashsplit(char *s)
     return r;
 }
 
-/* expands symlinks and .. or . expressions */
+/* expands symlinks and .. or . expressions
+ *
+ * Puts the result in the global "xbuf"
+ *
+ * If "full" is true, resolve one level of symlinks only.
+ *
+ * WARNING: This will segfault on symlink loops (thread: workers/45282)
+ */
 
 /**/
 static int
@@ -1050,10 +1057,10 @@ void
 print_if_link(char *s, int all)
 {
     if (*s == '/') {
-	*xbuf = '\0';
 	if (all) {
 	    char *start = s + 1;
 	    char xbuflink[PATH_MAX+1];
+	    *xbuf = '\0';
 	    for (;;) {
 		if (xsymlinks(start, 0) > 0) {
 		    printf(" -> ");
@@ -1068,8 +1075,11 @@ print_if_link(char *s, int all)
 		}
 	    }
 	} else {
-	    if (xsymlinks(s + 1, 1) > 0)
-		printf(" -> "), zputs(*xbuf ? xbuf : "/", stdout);
+	    if (chrealpath(&s, 'P', 0)) {
+		printf(" -> ");
+		zputs(*s ? s : "/", stdout);
+		zsfree(s);
+	    }
 	}
     }
 }