diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2017-12-01 02:19:44 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2017-12-03 00:24:52 +0900 |
commit | a1904a46630694d65ba333418cf0c9590598f3e5 (patch) | |
tree | 080210d6431fa03a8563a6fba5589ca7d7174fc9 /src/basic/fs-util.c | |
parent | 1ff8b31d9b611b91b0b0d3ab9343c29df4ecde56 (diff) | |
download | systemd-a1904a46630694d65ba333418cf0c9590598f3e5.tar.gz |
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/fs-util.c')
-rw-r--r-- | src/basic/fs-util.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 475400177a..3fe5c7cf13 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -722,6 +722,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; @@ -794,6 +798,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; } |