]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
tools: Handle archive_match errors
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 18 Mar 2026 13:55:56 +0000 (14:55 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 9 May 2026 10:18:38 +0000 (12:18 +0200)
These functions can return negative values, in which case operation
itself failed. While internal libarchive libraries handle these cases,
the tools don't. Check for negative values in them as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
cpio/cpio.c
tar/read.c
tar/write.c

index 6e6c2c3356c02ea33c3510846892b43188b29646..ebdace394ceaa3e7969a3f00ddd0fdf4016e8692 100644 (file)
@@ -1002,7 +1002,10 @@ mode_in(struct cpio *cpio)
                        lafe_errc(1, archive_errno(a),
                            "%s", archive_error_string(a));
                }
-               if (archive_match_path_excluded(cpio->matching, entry))
+               r = archive_match_path_excluded(cpio->matching, entry);
+               if (r < 0)
+                       lafe_errc(1, 0, "%s", archive_error_string(cpio->matching));
+               if (r)
                        continue;
                if (cpio->option_rename)
                        cpio_rename(entry);
@@ -1117,7 +1120,10 @@ mode_list(struct cpio *cpio)
                        lafe_errc(1, archive_errno(a),
                            "%s", archive_error_string(a));
                }
-               if (archive_match_path_excluded(cpio->matching, entry))
+               r = archive_match_path_excluded(cpio->matching, entry);
+               if (r < 0)
+                       lafe_errc(1, 0, "%s", archive_error_string(cpio->matching));
+               if (r)
                        continue;
                if (cpio->verbose)
                        list_item_verbose(cpio, entry);
index 4acbf6b2a9dc1c29b6a5977f0b022e9b5658e6f0..57ae5200cf0d69d13da73093afb543918aa669d7 100644 (file)
@@ -234,9 +234,14 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
        for (;;) {
                /* Support --fast-read option */
                const char *p;
-               if ((bsdtar->flags & OPTFLAG_FAST_READ) &&
-                   archive_match_path_unmatched_inclusions(bsdtar->matching) == 0)
-                       break;
+
+               if (bsdtar->flags & OPTFLAG_FAST_READ) {
+                   r = archive_match_path_unmatched_inclusions(bsdtar->matching);
+                       if (r < 0)
+                               lafe_errc(1, 0, "%s", archive_error_string(a));
+                       if (!r)
+                               break;
+               }
 
                r = archive_read_next_header(a, &entry);
                progress_data.entry = entry;
@@ -282,7 +287,11 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
                 * rewrite, there would be no way to exclude foo1/bar
                 * while allowing foo2/bar.)
                 */
-               if (archive_match_excluded(bsdtar->matching, entry))
+               r = archive_match_excluded(bsdtar->matching, entry);
+               if (r == ARCHIVE_FATAL)
+                       lafe_errc(1, 0, "%s",
+                                   archive_error_string(bsdtar->matching));
+               if (r)
                        continue; /* Excluded by a pattern test. */
 
                if (mode == 't') {
@@ -395,7 +404,7 @@ unmatched_inclusions_warn(struct archive *matching, const char *msg)
            matching, &p)) == ARCHIVE_OK)
                lafe_warnc(0, "%s: %s", p, msg);
        if (r == ARCHIVE_FATAL)
-               lafe_errc(1, errno, "Out of memory");
+               lafe_errc(1, 0, "%s", archive_error_string(matching));
 
        return (archive_match_path_unmatched_inclusions(matching));
 }
index abff3831bcdaaa1bf35c8b9e3bf9a6ba126f4fad..302df020ad3a70d0531e6cb402605a29bf952427 100644 (file)
@@ -699,7 +699,18 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
        int e;
 
        while (ARCHIVE_OK == (e = archive_read_next_header(ina, &in_entry))) {
-               if (archive_match_excluded(bsdtar->matching, in_entry))
+               e = archive_match_excluded(bsdtar->matching, in_entry);
+               if (e < 0) {
+                       if (!bsdtar->verbose)
+                               lafe_errc(1, 0, "%s",
+                                   archive_error_string(bsdtar->matching));
+                       else {
+                               fprintf(stderr, ": %s",
+                                   archive_error_string(bsdtar->matching));
+                               exit(1);
+                       }
+               }
+               if (e)
                        continue;
                if(edit_pathname(bsdtar, in_entry))
                        continue;