]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Check allocation in _archive_write_disk_header 3125/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 7 Jun 2026 13:49:46 +0000 (15:49 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 7 Jun 2026 13:49:46 +0000 (15:49 +0200)
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 <tobias@stoeckmann.org>
libarchive/archive_write_disk_posix.c
libarchive/archive_write_disk_windows.c

index 4e4e7d935024f3db046d4d5b0d13b06872c7c45d..da824f032a5969a5abda7a0db86eecf57f1db712 100644 (file)
@@ -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;
index 17f09e09164bea5bee43214a447de5b841849227..2b125d32cac95c5e5573c8ae69ac47f78e105c85 100644 (file)
@@ -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;