fs-util: change chase_symlinks() behaviour in regards to escaping the root dir
Previously, we'd generate an EINVAL error if it is attempted to escape a root directory with relative ".." symlinks. With this commit this is changed so that ".." from the root directory is a NOP, following the kernel's own behaviour where /.. is equivalent to /. As suggested by @keszybz.
This commit is contained in:
@@ -97,21 +97,21 @@ static void test_chase_symlinks(void) {
|
||||
|
||||
result = mfree(result);
|
||||
r = chase_symlinks(p, temp, &result);
|
||||
assert_se(r == -EINVAL);
|
||||
assert_se(r == 0 && path_equal(result, temp));
|
||||
|
||||
p = strjoina(temp, "/6dotsusr");
|
||||
assert_se(symlink("../../../usr", p) >= 0);
|
||||
|
||||
result = mfree(result);
|
||||
r = chase_symlinks(p, temp, &result);
|
||||
assert_se(r == -EINVAL);
|
||||
assert_se(r == 0 && path_equal(result, q));
|
||||
|
||||
p = strjoina(temp, "/top/8dotsusr");
|
||||
assert_se(symlink("../../../../usr", p) >= 0);
|
||||
|
||||
result = mfree(result);
|
||||
r = chase_symlinks(p, temp, &result);
|
||||
assert_se(r == -EINVAL);
|
||||
assert_se(r == 0 && path_equal(result, q));
|
||||
|
||||
/* Paths that contain repeated slashes */
|
||||
|
||||
@@ -137,7 +137,7 @@ static void test_chase_symlinks(void) {
|
||||
|
||||
result = mfree(result);
|
||||
r = chase_symlinks("/etc/./.././", "/etc", &result);
|
||||
assert_se(r == -EINVAL);
|
||||
assert_se(r == 0 && path_equal(result, "/etc"));
|
||||
|
||||
result = mfree(result);
|
||||
r = chase_symlinks("/etc/machine-id/foo", NULL, &result);
|
||||
|
||||
Reference in New Issue
Block a user