From: subotac <73706465+subotac@users.noreply.github.com> Date: Thu, 30 Jul 2026 15:40:17 +0000 (+0300) Subject: Fix absolute path test when run as root X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83a023ee3017b5994fe078a76d82aa54ef3151ee;p=thirdparty%2Flibarchive.git Fix absolute path test when run as root --- diff --git a/tar/test/test_option_P_upper.c b/tar/test/test_option_P_upper.c index 69810a304..2ed31b59d 100644 --- a/tar/test/test_option_P_upper.c +++ b/tar/test/test_option_P_upper.c @@ -20,7 +20,7 @@ DEFINE_TEST(test_extract_tar_absolute_paths) int r; // Create an absolute path for a test file inside testworkdir. - char *entry_suffix = "/tar-noabs"; + char *entry_suffix = "/work/tar-noabs"; size_t entry_suffix_length = strlen(entry_suffix); size_t testworkdir_length = strlen(testworkdir); size_t temp_absolute_file_name_length = testworkdir_length + entry_suffix_length; @@ -28,6 +28,10 @@ DEFINE_TEST(test_extract_tar_absolute_paths) assertEqualInt(snprintf(temp_absolute_file_name, temp_absolute_file_name_length + 1, "%s%s", testworkdir, entry_suffix), temp_absolute_file_name_length); + // Use a directory owned by the unprivileged test user. + assertMakeDir("work", 0755); + assertChdir("work"); + #if defined(_WIN32) && !defined(__CYGWIN__) // I'm unsure how to specify paths with spaces for the test invocation on windows. // Adding quotes doesn't seem to work. We should find a way to escape these paths, @@ -62,14 +66,15 @@ DEFINE_TEST(test_extract_tar_absolute_paths) // Check that the mangled path exists. #if defined(_WIN32) && !defined(__CYGWIN__) assertFileExists(temp_absolute_file_name + 3); // Skip the drive letter, colon and slash. - UNLINK(temp_absolute_file_name + 3); #else assertFileExists(temp_absolute_file_name + 1); // Skip the slash. - UNLINK(temp_absolute_file_name + 1); #endif - // Extracting the archive with -P / --absolute-paths should create the file. - r = systemf("%s --absolute-paths -xf test.tar", testprog); + // Extracting the archive with -P / --absolute-paths in a new directory should + // create the file without creating a mangled path. + assertMakeDir("with-P", 0755); + assertChdir("with-P"); + r = systemf("%s --absolute-paths -xf ../test.tar", testprog); assertEqualInt(r, 0); assertFileExists(temp_absolute_file_name);