]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use calloc instead of malloc to clear the memory from leftovers (#2207)
authorLukas Javorsky <ljavorsk@redhat.com>
Tue, 11 Jun 2024 04:41:25 +0000 (06:41 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Jun 2024 04:41:25 +0000 (21:41 -0700)
This ensures that the buffer is properly initialized and does not
contain any leftover data from previous operations. It is used later in
the `archive_entry_copy_hardlink_l` function call and could be
uninitialized.

libarchive/archive_read_support_format_iso9660.c
libarchive/archive_read_support_format_xar.c

index db5cdb67f1cf3c367f206bdc0f3a3eb271a99814..25ab11bf5964b286b83243b092823cc6b5bbbb0f 100644 (file)
@@ -1212,7 +1212,7 @@ archive_read_format_iso9660_read_header(struct archive_read *a,
                        }
                }
                if (iso9660->utf16be_previous_path == NULL) {
-                       iso9660->utf16be_previous_path = malloc(UTF16_NAME_MAX);
+                       iso9660->utf16be_previous_path = calloc(1, UTF16_NAME_MAX);
                        if (iso9660->utf16be_previous_path == NULL) {
                                archive_set_error(&a->archive, ENOMEM,
                                    "No memory");
@@ -3033,7 +3033,7 @@ heap_add_entry(struct archive_read *a, struct heap_queue *heap,
                        return (ARCHIVE_FATAL);
                }
                new_pending_files = (struct file_info **)
-                   malloc(new_size * sizeof(new_pending_files[0]));
+                   calloc(new_size, sizeof(new_pending_files[0]));
                if (new_pending_files == NULL) {
                        archive_set_error(&a->archive,
                            ENOMEM, "Out of memory");
index b9bef05161d3e3a460dbf92face07cad0d610a3f..dbc31df94e01b64698e14a3666dde5f2b0deb78d 100644 (file)
@@ -1242,7 +1242,7 @@ heap_add_entry(struct archive_read *a,
                        return (ARCHIVE_FATAL);
                }
                new_pending_files = (struct xar_file **)
-                   malloc(new_size * sizeof(new_pending_files[0]));
+                   calloc(new_size, sizeof(new_pending_files[0]));
                if (new_pending_files == NULL) {
                        archive_set_error(&a->archive,
                            ENOMEM, "Out of memory");