From: Tobias Stoeckmann Date: Sun, 7 Jun 2026 13:49:46 +0000 (+0200) Subject: Check allocation in _archive_write_disk_header X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cbf1f01a12d2ed1010dcd176bdd33cd3050952a;p=thirdparty%2Flibarchive.git Check allocation in _archive_write_disk_header The POSIX and Windows code did not check the result of archive_entry_clone. Handle this error condition properly. While at it, unify POSIX and Windows code a bit. Signed-off-by: Tobias Stoeckmann --- diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 4e4e7d935..da824f032 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -600,11 +600,12 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) a->pst = NULL; a->current_fixup = NULL; a->deferred = 0; - if (a->entry) { - archive_entry_free(a->entry); - a->entry = NULL; - } + archive_entry_free(a->entry); a->entry = archive_entry_clone(entry); + if (a->entry == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } a->fd = -1; a->fd_offset = 0; a->offset = 0; diff --git a/libarchive/archive_write_disk_windows.c b/libarchive/archive_write_disk_windows.c index 17f09e091..2b125d32c 100644 --- a/libarchive/archive_write_disk_windows.c +++ b/libarchive/archive_write_disk_windows.c @@ -859,8 +859,11 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) a->current_fixup = NULL; a->deferred = 0; archive_entry_free(a->entry); - a->entry = NULL; a->entry = archive_entry_clone(entry); + if (a->entry == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } a->fh = INVALID_HANDLE_VALUE; a->fd_offset = 0; a->offset = 0;