diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | Src/utils.c | 18 |
2 files changed, 16 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog index 58296c0df..d3d3e6ac3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2020-03-25 Daniel Shahaf <d.s@daniel.shahaf.name> + * 45583/0006: Src/utils.c: Don't use xsymlinks() in 'whence -s'. + * 45583/0005: Test/B13whence.ztst: Add a test for bin_whence's symlinks resolution. 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); + } } } } |