From: Alfred Wingate Date: Mon, 27 Nov 2023 01:29:11 +0000 (+0200) Subject: unzip: Increment option count after swallowing -- (#2022) X-Git-Tag: v3.7.3~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5aac7c9295449dc2fabf36f203f4ff464724ccf;p=thirdparty%2Flibarchive.git unzip: Increment option count after swallowing -- (#2022) * Option count is used later for the position of the file in the arguments and otherwise it uses -- as the file. --------- Signed-off-by: Alfred Wingate --- diff --git a/Makefile.am b/Makefile.am index 42424a233..f80535a71 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1503,6 +1503,7 @@ bsdunzip_test_SOURCES= \ unzip/test/test.h \ unzip/test/test_0.c \ unzip/test/test_basic.c \ + unzip/test/test_doubledash.c \ unzip/test/test_glob.c \ unzip/test/test_not_exist.c \ unzip/test/test_singlefile.c \ diff --git a/unzip/cmdline.c b/unzip/cmdline.c index 5ff5b7190..ab1aeb31f 100644 --- a/unzip/cmdline.c +++ b/unzip/cmdline.c @@ -113,6 +113,7 @@ bsdunzip_getopt(struct bsdunzip *bsdunzip) if (strcmp(bsdunzip->argv[0], "--") == 0) { ++bsdunzip->argv; --bsdunzip->argc; + bsdunzip_optind++; return (-1); } /* Get next word for parsing. */ diff --git a/unzip/test/CMakeLists.txt b/unzip/test/CMakeLists.txt index 20e730a9c..75ca0ee82 100644 --- a/unzip/test/CMakeLists.txt +++ b/unzip/test/CMakeLists.txt @@ -11,6 +11,7 @@ IF(ENABLE_UNZIP AND ENABLE_TEST) test.h test_0.c test_basic.c + test_doubledash.c test_glob.c test_singlefile.c test_C.c diff --git a/unzip/test/test_doubledash.c b/unzip/test/test_doubledash.c new file mode 100644 index 000000000..eb7d34e4f --- /dev/null +++ b/unzip/test/test_doubledash.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Adrian Vovk + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" + +/* Test double dash arg - swallow "--" and use next argument as file name */ +DEFINE_TEST(test_doubledash) +{ + const char *reffile = "test_basic.zip"; + int r; + + extract_reference_file(reffile); + r = systemf("%s -- %s >test.out 2>test.err", testprog, reffile); + assertEqualInt(0, r); + assertNonEmptyFile("test.out"); + assertEmptyFile("test.err"); + + assertTextFileContents("contents a\n", "test_basic/a"); + assertTextFileContents("contents b\n", "test_basic/b"); + assertTextFileContents("contents c\n", "test_basic/c"); + assertTextFileContents("contents CAPS\n", "test_basic/CAPS"); +}