]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
unzip: Increment option count after swallowing -- (#2022)
authorAlfred Wingate <parona@protonmail.com>
Mon, 27 Nov 2023 01:29:11 +0000 (03:29 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 01:29:11 +0000 (17:29 -0800)
* 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 <parona@protonmail.com>
Makefile.am
unzip/cmdline.c
unzip/test/CMakeLists.txt
unzip/test/test_doubledash.c [new file with mode: 0644]

index 42424a2334ccb21139d9f7f14ef9d61483e097e0..f80535a71a1c5e868b7d9f17496f2ff176395cf4 100644 (file)
@@ -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 \
index 5ff5b719024ab7fe56916689fb1bd07293eae57b..ab1aeb31fe1878be5b28104bed06543073e9fd6b 100644 (file)
@@ -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. */
index 20e730a9cdcab3bedd5643797eeaa6d97c5cef33..75ca0ee829be0a6c29a3da50124050b9f38cf564 100644 (file)
@@ -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 (file)
index 0000000..eb7d34e
--- /dev/null
@@ -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");
+}