Skip to content

Commit

Permalink
Use calloc instead of malloc to clear the memory from leftovers (liba…
Browse files Browse the repository at this point in the history
…rchive#2207)

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.
  • Loading branch information
ljavorsk authored Jun 11, 2024
1 parent 98f7bbd commit ffa43ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libarchive/archive_read_support_format_iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_support_format_xar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit ffa43ae

Please sign in to comment.