]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-fs-util: test chase_symlinks with user-owned dirs 11820/head
authorDavid Michael <dm0@redhat.com>
Tue, 26 Feb 2019 18:31:28 +0000 (13:31 -0500)
committerDavid Michael <dm0@redhat.com>
Thu, 28 Feb 2019 18:06:07 +0000 (13:06 -0500)
This verifies the fix for the issue described in:
https://github.com/systemd/systemd/pull/11820

src/test/test-fs-util.c

index e049abc4a40b03ee66c6d55e7b249024112d477b..f0f015056e24d78c73e2625bbd91dfa8933fa801 100644 (file)
@@ -154,6 +154,30 @@ static void test_chase_symlinks(void) {
         assert_se(path_equal(result, q));
         result = mfree(result);
 
+        /* Paths underneath the "root" with different UIDs while using CHASE_SAFE */
+
+        if (geteuid() == 0) {
+                p = strjoina(temp, "/user");
+                assert_se(mkdir(p, 0755) >= 0);
+                assert_se(chown(p, UID_NOBODY, GID_NOBODY) >= 0);
+
+                q = strjoina(temp, "/user/root");
+                assert_se(mkdir(q, 0755) >= 0);
+
+                p = strjoina(q, "/link");
+                assert_se(symlink("/", p) >= 0);
+
+                /* Fail when user-owned directories contain root-owned subdirectories. */
+                r = chase_symlinks(p, temp, CHASE_SAFE, &result);
+                assert_se(r == -ENOLINK);
+                result = mfree(result);
+
+                /* Allow this when the user-owned directories are all in the "root". */
+                r = chase_symlinks(p, q, CHASE_SAFE, &result);
+                assert_se(r > 0);
+                result = mfree(result);
+        }
+
         /* Paths using . */
 
         r = chase_symlinks("/etc/./.././", NULL, 0, &result);