summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.c
diff options
context:
space:
mode:
author3chas3 <ciwillia@brocade.com>2017-01-31 08:21:15 -0500
committerSven Eden <yamakuzure@gmx.net>2017-07-17 17:58:36 +0200
commitc59c21d77cea613cc662901b421e4d3a0fcd854f (patch)
tree68686003d8ff953caa8655937ebffcd356c391e6 /src/basic/fs-util.c
parenta5c28308446550e0966825472babdf123fc976ac (diff)
util-lib: Fix chase_symlinks() with absolute symlinks (#5185)
If chase_symlinks() encouters an absolute symlink, it resets the todo buffer to just the newly discovered symlink and discards any of the remaining previous symlink path. Regardless of whether or not the symlink is absolute or relative, we need to preserve the remainder of the path that has not yet been resolved.
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r--src/basic/fs-util.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 05f10c86f..f6fb7cabc 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -728,6 +728,8 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
return -errno;
if (S_ISLNK(st.st_mode)) {
+ char *joined;
+
_cleanup_free_ char *destination = NULL;
/* This is a symlink, in this case read the destination. But let's make sure we don't follow
@@ -751,9 +753,6 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
if (fd < 0)
return -errno;
- free_and_replace(buffer, destination);
-
- todo = buffer;
free(done);
/* Note that we do not revalidate the root, we take it as is. */
@@ -765,19 +764,17 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
return -ENOMEM;
}
- } else {
- char *joined;
+ }
- /* A relative destination. If so, this is what we'll prefix what's left to do with what
- * we just read, and start the loop again, but remain in the current directory. */
+ /* Prefix what's left to do with what we just read, and start the loop again,
+ * but remain in the current directory. */
- joined = strjoin("/", destination, todo);
- if (!joined)
- return -ENOMEM;
+ joined = strjoin("/", destination, todo);
+ if (!joined)
+ return -ENOMEM;
- free(buffer);
- todo = buffer = joined;
- }
+ free(buffer);
+ todo = buffer = joined;
continue;
}