From: Tobias Stoeckmann Date: Mon, 22 Jun 2026 20:29:11 +0000 (+0200) Subject: unzip: Add symlink tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34b3da0013ae7ff64f0fbb2ad1c0f01d2ff846d4;p=thirdparty%2Flibarchive.git unzip: Add symlink tests Verify that symlink creations and overwriting works, i.e. that dangling symlinks are properly overwritten. Signed-off-by: Tobias Stoeckmann --- diff --git a/Makefile.am b/Makefile.am index f136c3a1d..8ac57db21 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1710,6 +1710,7 @@ bsdunzip_test_SOURCES= \ unzip/test/test_n.c \ unzip/test/test_o.c \ unzip/test/test_q.c \ + unzip/test/test_symlink.c \ unzip/test/test_t.c \ unzip/test/test_t_bad.c \ unzip/test/test_u.c \ @@ -1746,6 +1747,8 @@ bsdunzip_test_EXTRA_DIST= \ unzip/test/test_f_new.zip.uu \ unzip/test/test_f_old.zip.uu \ unzip/test/test_singlefile.zip.uu \ + unzip/test/test_symlink_1.zip.uu \ + unzip/test/test_symlink_2.zip.uu \ unzip/test/test_t_bad.zip.uu \ unzip/test/test_u_new.zip.uu \ unzip/test/test_u_old.zip.uu \ diff --git a/unzip/test/CMakeLists.txt b/unzip/test/CMakeLists.txt index 55d4d4b95..0aee8a173 100644 --- a/unzip/test/CMakeLists.txt +++ b/unzip/test/CMakeLists.txt @@ -15,6 +15,7 @@ IF(ENABLE_UNZIP AND ENABLE_TEST) test_glob.c test_not_exist.c test_singlefile.c + test_symlink.c test_C.c test_p.c test_d.c diff --git a/unzip/test/test_symlink.c b/unzip/test/test_symlink.c new file mode 100644 index 000000000..3ee29977d --- /dev/null +++ b/unzip/test/test_symlink.c @@ -0,0 +1,52 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 Tobias Stoeckmann + * All rights reserved. + */ +#include "test.h" + +/* Test symlinks */ +DEFINE_TEST(test_symlink) +{ + const char *reffile1 = "test_symlink_1.zip"; + const char *reffile2 = "test_symlink_2.zip"; + int r; + + if (!canSymlink()) { + skipping("System cannot create symlinks."); + return; + } + + extract_reference_file(reffile1); + extract_reference_file(reffile2); + + /* Extract first archive */ + r = systemf("%s %s >test.out 2>test.err", testprog, reffile1); + assertEqualInt(0, r); + assertNonEmptyFile("test.out"); + assertNonEmptyFile("test.err"); + assertIsDir("dir", 0755); + assertIsSymlink("dlink", "dir", 1); + assertIsReg("file.txt", 0644); + assertIsSymlink("flink", "file.txt", 0); + assertFileNotExists("link.insecure"); + + /* Create dangling symlinks by deleting targets */ + rmdir("dir"); + unlink("file.txt"); + assertFileNotExists("dir"); + assertFileNotExists("file.txt"); + assertIsSymlink("dlink", "dir", 1); + assertIsSymlink("flink", "file.txt", 0); + + /* Extract second archive, overwriting dangling symlinks */ + r = systemf("%s -o %s >test.out 2>test.err", testprog, reffile2); + assertEqualInt(0, r); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertFileNotExists("dir"); + assertIsDir("dlink", 0755); + assertTextFileContents("hello world\n", "dlink/file.txt"); + assertIsReg("flink", 0644); +} diff --git a/unzip/test/test_symlink_1.zip.uu b/unzip/test/test_symlink_1.zip.uu new file mode 100644 index 000000000..60b9a69c5 --- /dev/null +++ b/unzip/test/test_symlink_1.zip.uu @@ -0,0 +1,21 @@ +begin 644 test_symlink_1.zip +M4$L#!!0``````)&NUEP````````````````$`"``9&ER+W5X"P`!!.@#```$ +MZ`,``%54#0`'@I(Y:H*2.6J"DCEJ4$L#!!0``````)"NUEP0>JNZ`P````,` +M```%`"``9&QI;FMU>`L``03H`P``!.@#``!55`T`!X"2.6J`DCEJ@)(Y:F1I +M+DCEJBY(Y:HN2.6I02P<(````````````````4$L# +M!!0``````)>NUEPE%O?@"`````@````%`"``9FQI;FMU>`L``03H`P``!.@# +M``!55`T`!X^2.6J/DCEJCY(Y:F9I;&4N='AT4$L#!!0``````(RNUEP&4/WP +M"@````H````-`"``:6YS96-U9(Y:GF2.6IYDCEJ+BXO;W5T`L``03H`P``!.@#``!55`T`!^^2.6KODCEJ[Y(Y:FAE;&QO('=O3.6H)DSEJ8V]N=&5N="!F +M;&EN:PI02P<(%P(`(PX````.````4$L!`@H#"@`(````RZ[67"T["*\,```` +M#`````X`&````````````*2!`````&1L:6YK+V9I;&4N='AT=7@+``$$Z`,` +M``3H`P``550%``'ODCEJ4$L!`@H#"@`(````V*[67!<"`",.````#@````4` +M&````````````*2!:````&9L:6YK=7@+``$$Z`,```3H`P``550%``$)DSEJ +64$L%!@`````"``(`GP```,D````````` +` +end