summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-11-26 22:18:58 -0500
committerLennart Poettering <lennart@poettering.net>2016-12-01 00:25:51 +0100
commitdf878e682d009bc3c0842499fedc44703a7e7ede (patch)
tree68e0ba826e26b8a9081b3f18718405ca51d0237b /src
parent68cf43c3154cd18bfdf46df07f854d8272062ab9 (diff)
test-fs-util: add a test case with repeated ".." parts that would escape the root
Diffstat (limited to 'src')
-rw-r--r--src/test/test-fs-util.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 53a3cdc663..7c6deb5416 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -60,6 +60,8 @@ static void test_chase_symlinks(void) {
p = strjoina(temp, "/start");
assert_se(symlink("top/dot/dotdota", p) >= 0);
+ /* Paths that use symlinks underneath the "root" */
+
r = chase_symlinks(p, NULL, &result);
assert_se(r >= 0);
assert_se(path_equal(result, "/usr"));
@@ -88,6 +90,31 @@ static void test_chase_symlinks(void) {
assert_se(r >= 0);
assert_se(path_equal(result, temp));
+ /* Paths that would "escape" outside of the "root" */
+
+ p = strjoina(temp, "/6dots");
+ assert_se(symlink("../../..", p) >= 0);
+
+ result = mfree(result);
+ r = chase_symlinks(p, temp, &result);
+ assert_se(r == -EINVAL);
+
+ p = strjoina(temp, "/6dotsusr");
+ assert_se(symlink("../../../usr", p) >= 0);
+
+ result = mfree(result);
+ r = chase_symlinks(p, temp, &result);
+ assert_se(r == -EINVAL);
+
+ p = strjoina(temp, "/top/8dotsusr");
+ assert_se(symlink("../../../../usr", p) >= 0);
+
+ result = mfree(result);
+ r = chase_symlinks(p, temp, &result);
+ assert_se(r == -EINVAL);
+
+ /* Paths that contain repeated slashes */
+
p = strjoina(temp, "/slashslash");
assert_se(symlink("///usr///", p) >= 0);
@@ -101,6 +128,8 @@ static void test_chase_symlinks(void) {
assert_se(r >= 0);
assert_se(path_equal(result, q));
+ /* Paths using . */
+
result = mfree(result);
r = chase_symlinks("/etc/./.././", NULL, &result);
assert_se(r >= 0);
@@ -114,6 +143,8 @@ static void test_chase_symlinks(void) {
r = chase_symlinks("/etc/machine-id/foo", NULL, &result);
assert_se(r == -ENOTDIR);
+ /* Path that loops back to self */
+
result = mfree(result);
p = strjoina(temp, "/recursive-symlink");
assert_se(symlink("recursive-symlink", p) >= 0);