diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-13 17:08:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-13 17:09:05 +0200 |
commit | 070aa6174728d35077d98e875717358ccfbf2870 (patch) | |
tree | bbbecadc99d4619b3e45a0e2b90242465fc22974 /libbb | |
parent | 84d38500a7f7cf961ea0cf075c372f0a48b2f1f8 (diff) | |
download | busybox-070aa6174728d35077d98e875717358ccfbf2870.tar.gz |
readlink,realpath: fix a case with a symplink, closes 11021
function old new delta
xmalloc_realpath_coreutils 125 201 +76
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xreadlink.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index ead30e499..a4e402b84 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c @@ -147,6 +147,35 @@ char* FAST_FUNC xmalloc_realpath_coreutils(const char *path) buf[len++] = '/'; strcpy(buf + len, last_slash); } + } else { + char *link = xmalloc_readlink(path); + if (link) { + char *cwd; + if (link[0] == '/') { + /* + * $ ln -s /bin/qwe symlink # note: /bin is a link to /usr/bin + * $ readlink -f symlink + * /usr/bin/qwe/target_does_not_exist + * $ realpath symlink + * /usr/bin/qwe/target_does_not_exist + */ + buf = xmalloc_realpath_coreutils(link); + free(link); + return buf; + } + /* + * $ ln -s target_does_not_exist symlink + * $ readlink -f symlink + * /CURDIR/target_does_not_exist + * $ realpath symlink + * /CURDIR/target_does_not_exist + */ + cwd = xrealloc_getcwd_or_warn(NULL); + buf = concat_path_file(cwd, link); + free(cwd); + free(link); + return buf; + } } } |