From 6efb1257d10cd1ecdae6208d083af36f15e4c05f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 28 Jan 2020 21:40:58 +0100 Subject: [PATCH] test: add test for the non-resolving of chase_symlink() root prefix --- src/test/test-fs-util.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index ac8b95aece0..d5492d937b9 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -371,6 +371,15 @@ static void test_chase_symlinks(void) { assert_se(streq("/usr", result)); result = mfree(result); + /* Make sure that symlinks in the "root" path are not resolved, but those below are */ + p = strjoina("/etc/..", temp, "/self"); + assert_se(symlink(".", p) >= 0); + q = strjoina(p, "/top/dot/dotdota"); + r = chase_symlinks(q, p, 0, &result, NULL); + assert_se(r > 0); + assert_se(path_equal(path_startswith(result, p), "usr")); + result = mfree(result); + cleanup: assert_se(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); }