summaryrefslogtreecommitdiff
path: root/Src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/utils.c')
-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);
+ }
}
}
}