Merge pull request #2927 from stoeckmann/pathmatch_recursion

archive_match: Prevent call stack overflow
This commit is contained in:
Tim Kientzle authored and GitHub committed 2026-05-09 13:48:20 -07:00
commit 5aa477220e
8 files changed
+93 -35

No files matched your search

+14 -5
View 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));
}
+12 -1
View 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;