From: Tobias Stoeckmann Date: Wed, 18 Mar 2026 13:55:56 +0000 (+0100) Subject: tools: Handle archive_match errors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a62d049ea492f8959acd2e8100e5fc70fe6cbdb;p=thirdparty%2Flibarchive.git tools: Handle archive_match errors 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 --- diff --git a/cpio/cpio.c b/cpio/cpio.c index 6e6c2c335..ebdace394 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -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); diff --git a/tar/read.c b/tar/read.c index 4acbf6b2a..57ae5200c 100644 --- a/tar/read.c +++ b/tar/read.c @@ -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)); } diff --git a/tar/write.c b/tar/write.c index abff3831b..302df020a 100644 --- a/tar/write.c +++ b/tar/write.c @@ -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;