]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: extra safety checks on chase_symlinks() root parameter
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Jan 2018 10:56:52 +0000 (11:56 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Jan 2018 11:04:15 +0000 (12:04 +0100)
Let's handle root="" and root="/" safely.

src/basic/fs-util.c

index 068f5660fa270bc3f008d065effaeb0bd5ab219b..15f9958c05dd0a90fd65ee7d194f0c9ea1aff699 100644 (file)
@@ -657,6 +657,14 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
          * function what to do when encountering a symlink with an absolute path as directory: prefix it by the
          * specified path. */
 
+        if (original_root) {
+                if (isempty(original_root)) /* What's this even supposed to mean? */
+                        return -EINVAL;
+
+                if (path_equal(original_root, "/")) /* A root directory of "/" is identical to none */
+                        original_root = NULL;
+        }
+
         if (original_root) {
                 r = path_make_absolute_cwd(original_root, &root);
                 if (r < 0)