summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2017-12-01 02:19:44 +0900
committerSven Eden <yamakuzure@gmx.net>2017-12-01 02:19:44 +0900
commit19c4e17bdc255030e9a2ca67f1349eefdca414d2 (patch)
treebfb4d0e072dec182161aae66e359db269e614344 /src/basic
parent4e26aad6f96fc8f2c80e5414abe28c347aa4a428 (diff)
fs-util: chase_symlinks(): remove unnecessary slash at the head
Before this, chase_symlinks("/../../foo/bar",...) returns //foo/bar. This removes the unnecessary slash at the head.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/fs-util.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index d63eeb1d2..df8ed643a 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -728,6 +728,10 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
* what we got so far. But don't allow this if the remaining path contains "../ or "./"
* or something else weird. */
+ /* If done is "/", as first also contains slash at the head, then remove this redundant slash. */
+ if (streq_ptr(done, "/"))
+ *done = '\0';
+
if (!strextend(&done, first, todo, NULL))
return -ENOMEM;
@@ -800,6 +804,10 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
done = first;
first = NULL;
} else {
+ /* If done is "/", as first also contains slash at the head, then remove this redundant slash. */
+ if (streq(done, "/"))
+ *done = '\0';
+
if (!strextend(&done, first, NULL))
return -ENOMEM;
}