From 12347c26ce2041e9c06abb0a42d1fa759c4a0551 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 21 Mar 2020 19:09:04 +0000 Subject: 45583/0006: Don't use xsymlinks() in 'whence -s'. --- Src/utils.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'Src/utils.c') 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); + } } } } -- cgit 1.4.1