]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 708: tar should fail if a named input file is missing
authorTim Kientzle <kientzle@acm.org>
Sat, 28 May 2016 19:39:10 +0000 (12:39 -0700)
committerTim Kientzle <kientzle@acm.org>
Sat, 28 May 2016 19:39:18 +0000 (12:39 -0700)
Tar was exiting with success if an input file named on the command
line was not present.

Includes tests for both bsdtar and bsdcpio to ensure this does
not regress.

Makefile.am
cpio/test/CMakeLists.txt
cpio/test/test_missing_file.c [new file with mode: 0644]
tar/test/CMakeLists.txt
tar/test/test_missing_file.c [new file with mode: 0644]
tar/write.c

index c5250184a71ef4f4fbc2e9c40917209ae3cd8e76..4a196735876ff9257bcbcdb7b75f05332e47d1d2 100644 (file)
@@ -909,6 +909,7 @@ bsdtar_test_SOURCES= \
        tar/test/test_format_newc.c \
        tar/test/test_help.c \
        tar/test/test_leading_slash.c \
+       tar/test/test_missing_file.c \
        tar/test/test_option_C_upper.c \
        tar/test/test_option_H_upper.c \
        tar/test/test_option_L_upper.c \
@@ -1064,6 +1065,7 @@ bsdcpio_test_SOURCES= \
        cpio/test/test_extract_cpio_xz.c \
        cpio/test/test_format_newc.c \
        cpio/test/test_gcpio_compat.c \
+       cpio/test/test_missing_file.c \
        cpio/test/test_option_0.c \
        cpio/test/test_option_B_upper.c \
        cpio/test/test_option_C_upper.c \
index f2c27540813d1afe60b6e10557e8583aba9a5efe..e3063ee9be583c45b3b43bc02acca41968b4a1eb 100644 (file)
@@ -25,6 +25,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST)
     test_extract_cpio_xz
     test_format_newc.c
     test_gcpio_compat.c
+    test_missing_file.c
     test_option_0.c
     test_option_B_upper.c
     test_option_C_upper.c
diff --git a/cpio/test/test_missing_file.c b/cpio/test/test_missing_file.c
new file mode 100644 (file)
index 0000000..a908f53
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2016 Tim Kientzle
+ * 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.
+ * 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"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_missing_file)
+{
+       int r;
+
+       assertMakeFile("file1", 0644, "file1");
+       assertMakeFile("file2", 0644, "file2");
+
+       assertMakeFile("filelist1", 0644, "file1\nfile2\n");
+       r = systemf("%s -o <filelist1 >stdout1 2>stderr1", testprog);
+       assertEqualInt(r, 0);
+       assertTextFileContents("1 block\n", "stderr1");
+
+       assertMakeFile("filelist2", 0644, "file1\nfile2\nfile3\n");
+       r = systemf("%s -o <filelist2 >stdout2 2>stderr2", testprog);
+       assert(r != 0);
+
+       assertMakeFile("filelist3", 0644, "");
+       r = systemf("%s -o <filelist3 >stdout3 2>stderr3", testprog);
+       assertEqualInt(r, 0);
+       assertTextFileContents("1 block\n", "stderr3");
+
+       assertMakeFile("filelist4", 0644, "file3\n");
+       r = systemf("%s -o <filelist4 >stdout4 2>stderr4", testprog);
+       assert(r != 0);
+}
index 9648e4892a3c0809c96d8cecd2babda9ef61216d..f19a5f69c504a4271c7d3fd55730d587a69f3603 100644 (file)
@@ -25,6 +25,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
     test_format_newc.c
     test_help.c
     test_leading_slash.c
+    test_missing_file.c
     test_option_C_upper.c
     test_option_H_upper.c
     test_option_L_upper.c
diff --git a/tar/test/test_missing_file.c b/tar/test/test_missing_file.c
new file mode 100644 (file)
index 0000000..e2e5da5
--- /dev/null
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (c) 2016 Tim Kientzle
+ * 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.
+ * 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"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_missing_file)
+{
+       assertMakeFile("file1", 0644, "file1");
+       assertMakeFile("file2", 0644, "file2");
+       assert(0 == systemf("%s -cf archive.tar file1 file2 2>stderr1", testprog));
+       assertEmptyFile("stderr1");
+       assert(0 != systemf("%s -cf archive.tar file1 file2 file3 2>stderr2", testprog));
+       assert(0 != systemf("%s -cf archive.tar 2>stderr3", testprog));
+       assert(0 != systemf("%s -cf archive.tar file3 2>stderr4", testprog));
+}
index 53b63834c419a7ec949120c907cfafff3e08b34c..2d076f488b5591b742ecfef16780b43204af4a10 100644 (file)
@@ -884,7 +884,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
                else if (r != ARCHIVE_OK) {
                        lafe_warnc(archive_errno(disk),
                            "%s", archive_error_string(disk));
-                       if (r == ARCHIVE_FATAL) {
+                       if (r == ARCHIVE_FATAL || r == ARCHIVE_FAILED) {
                                bsdtar->return_value = 1;
                                return;
                        } else if (r < ARCHIVE_WARN)