aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-06-13 17:08:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-06-13 17:09:05 +0200
commit070aa6174728d35077d98e875717358ccfbf2870 (patch)
treebbbecadc99d4619b3e45a0e2b90242465fc22974
parent84d38500a7f7cf961ea0cf075c372f0a48b2f1f8 (diff)
downloadbusybox-w32-070aa6174728d35077d98e875717358ccfbf2870.tar.gz
busybox-w32-070aa6174728d35077d98e875717358ccfbf2870.tar.bz2
busybox-w32-070aa6174728d35077d98e875717358ccfbf2870.zip
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>
-rw-r--r--libbb/xreadlink.c29
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)
147 buf[len++] = '/'; 147 buf[len++] = '/';
148 strcpy(buf + len, last_slash); 148 strcpy(buf + len, last_slash);
149 } 149 }
150 } else {
151 char *link = xmalloc_readlink(path);
152 if (link) {
153 char *cwd;
154 if (link[0] == '/') {
155 /*
156 * $ ln -s /bin/qwe symlink # note: /bin is a link to /usr/bin
157 * $ readlink -f symlink
158 * /usr/bin/qwe/target_does_not_exist
159 * $ realpath symlink
160 * /usr/bin/qwe/target_does_not_exist
161 */
162 buf = xmalloc_realpath_coreutils(link);
163 free(link);
164 return buf;
165 }
166 /*
167 * $ ln -s target_does_not_exist symlink
168 * $ readlink -f symlink
169 * /CURDIR/target_does_not_exist
170 * $ realpath symlink
171 * /CURDIR/target_does_not_exist
172 */
173 cwd = xrealloc_getcwd_or_warn(NULL);
174 buf = concat_path_file(cwd, link);
175 free(cwd);
176 free(link);
177 return buf;
178 }
150 } 179 }
151 } 180 }
152 181