chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:50:09 +0000 (07:50 +0200)
Let's handle root="" and root="/" safely.

src/basic/fs-util.c

index 32b1fb605b563384bfc88588386c69a93e452485..7a05e22ea52aa903cfcc20714cdac50834406f9c 100644 (file)
@@ -39,6 +39,7 @@
 #include "mkdir.h"
 #include "parse-util.h"
 #include "path-util.h"
+//#include "process-util.h"
 #include "stat-util.h"
 #include "stdio-util.h"
 #include "string-util.h"
@@ -671,6 +672,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)