mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 16:37:19 +09:00
test-fs-util: test chase_symlinks with user-owned dirs
This verifies the fix for the issue described in: https://github.com/systemd/systemd/pull/11820
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user