calloc: Use calloc() at most places
This modifies most of the places we do some form of: X = malloc(Y * Z); to use calloc(Y, Z) instead. Among other issues, this fixes: - allocation of integer overflow in grub_png_decode_image_header() reported by Chris Coulson, - allocation of integer overflow in luks_recover_key() reported by Chris Coulson, - allocation of integer overflow in grub_lvm_detect() reported by Chris Coulson. Fixes: CVE-2020-14308 Signed-off-by: Peter Jones <pjones@redhat.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
64e26162eb
commit
f725fa7cb2
87 changed files with 179 additions and 178 deletions
|
@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
|
|||
|
||||
grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize;
|
||||
grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *)
|
||||
grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms);
|
||||
grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym));
|
||||
|
||||
/* Relocators */
|
||||
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
|
||||
|
|
|
@ -554,11 +554,11 @@ grub_efiemu_mmap_sort_and_uniq (void)
|
|||
/* Initialize variables*/
|
||||
grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE);
|
||||
scanline_events = (struct grub_efiemu_mmap_scan *)
|
||||
grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num);
|
||||
grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2);
|
||||
|
||||
/* Number of chunks can't increase more than by factor of 2 */
|
||||
result = (grub_efi_memory_descriptor_t *)
|
||||
grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num);
|
||||
grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2);
|
||||
if (!result || !scanline_events)
|
||||
{
|
||||
grub_free (result);
|
||||
|
@ -660,7 +660,7 @@ grub_efiemu_mm_do_alloc (void)
|
|||
|
||||
/* Preallocate mmap */
|
||||
efiemu_mmap = (grub_efi_memory_descriptor_t *)
|
||||
grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t));
|
||||
grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t));
|
||||
if (!efiemu_mmap)
|
||||
{
|
||||
grub_efiemu_unload ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue