Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP1:GA
grub2.19065
0004-calloc-Use-calloc-at-most-places.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0004-calloc-Use-calloc-at-most-places.patch of Package grub2.19065
From 48eeedf1e4bd2a38acb44943e02a8e8ffab2060e Mon Sep 17 00:00:00 2001 From: Peter Jones <pjones@redhat.com> Date: Mon, 15 Jun 2020 12:26:01 -0400 Subject: [PATCH 4/7] 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> --- grub-core/bus/usb/usbhub.c | 8 ++++---- grub-core/commands/efi/lsefisystab.c | 3 ++- grub-core/commands/legacycfg.c | 6 +++--- grub-core/commands/menuentry.c | 2 +- grub-core/commands/nativedisk.c | 2 +- grub-core/commands/parttool.c | 12 +++++++++--- grub-core/commands/regexp.c | 2 +- grub-core/commands/search_wrap.c | 2 +- grub-core/disk/diskfilter.c | 4 ++-- grub-core/disk/ieee1275/ofdisk.c | 2 +- grub-core/disk/ldm.c | 14 +++++++------- grub-core/disk/luks.c | 2 +- grub-core/disk/lvm.c | 12 ++++++------ grub-core/disk/xen/xendisk.c | 2 +- grub-core/efiemu/loadcore.c | 2 +- grub-core/efiemu/mm.c | 6 +++--- grub-core/font/font.c | 3 +-- grub-core/fs/affs.c | 6 +++--- grub-core/fs/btrfs.c | 6 +++--- grub-core/fs/hfs.c | 2 +- grub-core/fs/hfsplus.c | 6 +++--- grub-core/fs/iso9660.c | 2 +- grub-core/fs/ntfs.c | 4 ++-- grub-core/fs/sfs.c | 2 +- grub-core/fs/tar.c | 2 +- grub-core/fs/udf.c | 4 ++-- grub-core/fs/zfs/zfs.c | 4 ++-- grub-core/gfxmenu/gui_string_util.c | 2 +- grub-core/gfxmenu/widget-box.c | 4 ++-- grub-core/io/gzio.c | 2 +- grub-core/kern/efi/efi.c | 6 +++--- grub-core/kern/emu/hostdisk.c | 2 +- grub-core/kern/fs.c | 2 +- grub-core/kern/misc.c | 2 +- grub-core/kern/parser.c | 2 +- grub-core/kern/uboot/uboot.c | 2 +- grub-core/lib/json/json.c | 2 +- grub-core/lib/libgcrypt/cipher/ac.c | 8 ++++---- grub-core/lib/libgcrypt/cipher/primegen.c | 4 ++-- grub-core/lib/libgcrypt/cipher/pubkey.c | 4 ++-- grub-core/lib/priority_queue.c | 2 +- grub-core/lib/reed_solomon.c | 7 +++---- grub-core/lib/relocator.c | 10 +++++----- grub-core/lib/zstd/fse_decompress.c | 2 +- grub-core/loader/arm/linux.c | 2 +- grub-core/loader/efi/chainloader.c | 2 +- grub-core/loader/i386/bsdXX.c | 2 +- grub-core/loader/i386/xnu.c | 4 ++-- grub-core/loader/macho.c | 2 +- grub-core/loader/multiboot_elfxx.c | 2 +- grub-core/loader/xnu.c | 2 +- grub-core/mmap/mmap.c | 4 ++-- grub-core/net/bootp.c | 2 +- grub-core/net/dns.c | 10 +++++----- grub-core/net/net.c | 4 ++-- grub-core/normal/charset.c | 10 +++++----- grub-core/normal/cmdline.c | 14 +++++++------- grub-core/normal/menu_entry.c | 14 +++++++------- grub-core/normal/menu_text.c | 4 ++-- grub-core/normal/term.c | 4 ++-- grub-core/osdep/linux/getroot.c | 6 +++--- grub-core/osdep/unix/config.c | 2 +- grub-core/osdep/windows/getroot.c | 2 +- grub-core/osdep/windows/hostdisk.c | 4 ++-- grub-core/osdep/windows/init.c | 2 +- grub-core/osdep/windows/platform.c | 4 ++-- grub-core/osdep/windows/relpath.c | 2 +- grub-core/partmap/gpt.c | 2 +- grub-core/partmap/msdos.c | 2 +- grub-core/script/execute.c | 2 +- grub-core/tests/fake_input.c | 2 +- grub-core/tests/video_checksum.c | 6 +++--- grub-core/video/capture.c | 2 +- grub-core/video/emu/sdl.c | 2 +- grub-core/video/i386/pc/vga.c | 2 +- grub-core/video/readers/png.c | 2 +- include/grub/unicode.h | 4 ++-- util/getroot.c | 2 +- util/grub-file.c | 2 +- util/grub-fstest.c | 4 ++-- util/grub-install-common.c | 2 +- util/grub-install.c | 4 ++-- util/grub-mkimagexx.c | 6 ++---- util/grub-mkrescue.c | 4 ++-- util/grub-mkstandalone.c | 2 +- util/grub-pe2elf.c | 12 +++++------- util/grub-probe.c | 4 ++-- 87 files changed, 179 insertions(+), 178 deletions(-) Index: grub-2.02/grub-core/bus/usb/usbhub.c =================================================================== --- grub-2.02.orig/grub-core/bus/usb/usbhub.c +++ grub-2.02/grub-core/bus/usb/usbhub.c @@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev) grub_usb_set_configuration (dev, 1); dev->nports = hubdesc.portcnt; - dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0])); - dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0])); + dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0])); + dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0])); if (!dev->children || !dev->ports) { grub_free (dev->children); @@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (g /* Query the number of ports the root Hub has. */ hub->nports = controller->dev->hubports (controller); - hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports); - hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports); + hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0])); + hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0])); if (!hub->devices || !hub->ports) { grub_free (hub->devices); Index: grub-2.02/grub-core/commands/efi/lsefisystab.c =================================================================== --- grub-2.02.orig/grub-core/commands/efi/lsefisystab.c +++ grub-2.02/grub-core/commands/efi/lsefisystab.c @@ -71,7 +71,8 @@ grub_cmd_lsefisystab (struct grub_comman grub_printf ("Vendor: "); for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++); - vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1); + /* Allocate extra 3 bytes to simplify math. */ + vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1); if (!vendor) return grub_errno; *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor, Index: grub-2.02/grub-core/commands/legacycfg.c =================================================================== --- grub-2.02.orig/grub-core/commands/legacycfg.c +++ grub-2.02/grub-core/commands/legacycfg.c @@ -314,7 +314,7 @@ grub_cmd_legacy_kernel (struct grub_comm if (argc < 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1)); + cutargs = grub_calloc (argc - 1, sizeof (cutargs[0])); if (!cutargs) return grub_errno; cutargc = argc - 1; @@ -436,7 +436,7 @@ grub_cmd_legacy_kernel (struct grub_comm { char rbuf[3] = "-r"; bsdargc = cutargc + 2; - bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc); + bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0])); if (!bsdargs) { err = grub_errno; @@ -559,7 +559,7 @@ grub_cmd_legacy_initrdnounzip (struct gr return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), "module"); - newargs = grub_malloc ((argc + 1) * sizeof (newargs[0])); + newargs = grub_calloc (argc + 1, sizeof (newargs[0])); if (!newargs) return grub_errno; grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0])); Index: grub-2.02/grub-core/commands/menuentry.c =================================================================== --- grub-2.02.orig/grub-core/commands/menuentry.c +++ grub-2.02/grub-core/commands/menuentry.c @@ -154,7 +154,7 @@ grub_normal_add_menu_entry (int argc, co goto fail; /* Save argc, args to pass as parameters to block arg later. */ - menu_args = grub_malloc (sizeof (char*) * (argc + 1)); + menu_args = grub_calloc (argc + 1, sizeof (char *)); if (! menu_args) goto fail; Index: grub-2.02/grub-core/commands/nativedisk.c =================================================================== --- grub-2.02.orig/grub-core/commands/nativedisk.c +++ grub-2.02/grub-core/commands/nativedisk.c @@ -194,7 +194,7 @@ grub_cmd_nativedisk (grub_command_t cmd else path_prefix = prefix; - mods = grub_malloc (argc * sizeof (mods[0])); + mods = grub_calloc (argc, sizeof (mods[0])); if (!mods) return grub_errno; Index: grub-2.02/grub-core/commands/parttool.c =================================================================== --- grub-2.02.orig/grub-core/commands/parttool.c +++ grub-2.02/grub-core/commands/parttool.c @@ -59,7 +59,13 @@ grub_parttool_register(const char *part_ for (nargs = 0; args[nargs].name != 0; nargs++); cur->nargs = nargs; cur->args = (struct grub_parttool_argdesc *) - grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); + grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc)); + if (!cur->args) + { + grub_free (cur); + curhandle--; + return -1; + } grub_memcpy (cur->args, args, (nargs + 1) * sizeof (struct grub_parttool_argdesc)); @@ -257,7 +263,7 @@ grub_cmd_parttool (grub_command_t cmd __ return err; } - parsed = (int *) grub_zalloc (argc * sizeof (int)); + parsed = (int *) grub_calloc (argc, sizeof (int)); for (i = 1; i < argc; i++) if (! parsed[i]) @@ -290,7 +296,7 @@ grub_cmd_parttool (grub_command_t cmd __ } ptool = cur; pargs = (struct grub_parttool_args *) - grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args)); + grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args)); for (j = i; j < argc; j++) if (! parsed[j]) { Index: grub-2.02/grub-core/commands/regexp.c =================================================================== --- grub-2.02.orig/grub-core/commands/regexp.c +++ grub-2.02/grub-core/commands/regexp.c @@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t c if (ret) goto fail; - matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1)); + matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches)); if (! matches) goto fail; Index: grub-2.02/grub-core/commands/search_wrap.c =================================================================== --- grub-2.02.orig/grub-core/commands/search_wrap.c +++ grub-2.02/grub-core/commands/search_wrap.c @@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t c for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) nhints++; - hints = grub_malloc (sizeof (hints[0]) * nhints); + hints = grub_calloc (nhints, sizeof (hints[0])); if (!hints) return grub_errno; j = 0; Index: grub-2.02/grub-core/disk/diskfilter.c =================================================================== --- grub-2.02.orig/grub-core/disk/diskfilter.c +++ grub-2.02/grub-core/disk/diskfilter.c @@ -1230,7 +1230,7 @@ grub_diskfilter_make_raid (grub_size_t u array->lvs->segments->node_count = nmemb; array->lvs->segments->raid_member_size = disk_size; array->lvs->segments->nodes - = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0])); + = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); array->lvs->segments->stripe_size = stripe_size; for (i = 0; i < nmemb; i++) { @@ -1322,7 +1322,7 @@ insert_array (grub_disk_t disk, const st grub_partition_t p; for (p = disk->partition; p; p = p->parent) s++; - pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0])); + pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0])); s = 0; for (p = disk->partition; p; p = p->parent) pv->partmaps[s++] = xstrdup (p->partmap->name); Index: grub-2.02/grub-core/disk/ieee1275/ofdisk.c =================================================================== --- grub-2.02.orig/grub-core/disk/ieee1275/ofdisk.c +++ grub-2.02/grub-core/disk/ieee1275/ofdisk.c @@ -297,7 +297,7 @@ dev_iterate (const struct grub_ieee1275_ /* Power machines documentation specify 672 as maximum SAS disks in one system. Using a slightly larger value to be safe. */ table_size = 768; - table = grub_malloc (table_size * sizeof (grub_uint64_t)); + table = grub_calloc (table_size, sizeof (grub_uint64_t)); if (!table) { Index: grub-2.02/grub-core/disk/ldm.c =================================================================== --- grub-2.02.orig/grub-core/disk/ldm.c +++ grub-2.02/grub-core/disk/ldm.c @@ -323,8 +323,8 @@ make_vg (grub_disk_t disk, lv->segments->type = GRUB_DISKFILTER_MIRROR; lv->segments->node_count = 0; lv->segments->node_alloc = 8; - lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes) - * lv->segments->node_alloc); + lv->segments->nodes = grub_calloc (lv->segments->node_alloc, + sizeof (*lv->segments->nodes)); if (!lv->segments->nodes) goto fail2; ptr = vblk[i].dynamic; @@ -543,8 +543,8 @@ make_vg (grub_disk_t disk, { comp->segment_alloc = 8; comp->segment_count = 0; - comp->segments = grub_malloc (sizeof (*comp->segments) - * comp->segment_alloc); + comp->segments = grub_calloc (comp->segment_alloc, + sizeof (*comp->segments)); if (!comp->segments) goto fail2; } @@ -590,8 +590,8 @@ make_vg (grub_disk_t disk, } comp->segments->node_count = read_int (ptr + 1, *ptr); comp->segments->node_alloc = comp->segments->node_count; - comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes) - * comp->segments->node_alloc); + comp->segments->nodes = grub_calloc (comp->segments->node_alloc, + sizeof (*comp->segments->nodes)); if (!lv->segments->nodes) goto fail2; } @@ -1017,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *d *nsectors = lv->size; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) Index: grub-2.02/grub-core/disk/luks.c =================================================================== --- grub-2.02.orig/grub-core/disk/luks.c +++ grub-2.02/grub-core/disk/luks.c @@ -336,7 +336,7 @@ luks_recover_key (grub_disk_t source, && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); - split_key = grub_malloc (keysize * max_stripes); + split_key = grub_calloc (keysize, max_stripes); if (!split_key) return grub_errno; Index: grub-2.02/grub-core/disk/lvm.c =================================================================== --- grub-2.02.orig/grub-core/disk/lvm.c +++ grub-2.02/grub-core/disk/lvm.c @@ -456,7 +456,7 @@ grub_lvm_detect (grub_disk_t disk, #endif goto lvs_fail; } - lv->segments = grub_zalloc (sizeof (*seg) * lv->segment_count); + lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); seg = lv->segments; for (i = 0; i < lv->segment_count; i++) @@ -513,8 +513,8 @@ grub_lvm_detect (grub_disk_t disk, if (seg->node_count != 1) seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); - seg->nodes = grub_zalloc (sizeof (*stripe) - * seg->node_count); + seg->nodes = grub_calloc (seg->node_count, + sizeof (*stripe)); stripe = seg->nodes; p = grub_strstr (p, "stripes = ["); Index: grub-2.02/grub-core/disk/xen/xendisk.c =================================================================== --- grub-2.02.orig/grub-core/disk/xen/xendisk.c +++ grub-2.02/grub-core/disk/xen/xendisk.c @@ -426,7 +426,7 @@ grub_xendisk_init (void) if (!ctr) return; - virtdisks = grub_malloc (ctr * sizeof (virtdisks[0])); + virtdisks = grub_calloc (ctr, sizeof (virtdisks[0])); if (!virtdisks) return; if (grub_xenstore_dir ("device/vbd", fill, &ctr)) Index: grub-2.02/grub-core/efiemu/loadcore.c =================================================================== --- grub-2.02.orig/grub-core/efiemu/loadcore.c +++ grub-2.02/grub-core/efiemu/loadcore.c @@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehd 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); Index: grub-2.02/grub-core/efiemu/mm.c =================================================================== --- grub-2.02.orig/grub-core/efiemu/mm.c +++ grub-2.02/grub-core/efiemu/mm.c @@ -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 (); Index: grub-2.02/grub-core/font/font.c =================================================================== --- grub-2.02.orig/grub-core/font/font.c +++ grub-2.02/grub-core/font/font.c @@ -293,8 +293,7 @@ load_font_index (grub_file_t file, grub_ font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE; /* Allocate the character index array. */ - font->char_index = grub_malloc (font->num_chars - * sizeof (struct char_index_entry)); + font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry)); if (!font->char_index) return 1; font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); Index: grub-2.02/grub-core/fs/affs.c =================================================================== --- grub-2.02.orig/grub-core/fs/affs.c +++ grub-2.02/grub-core/fs/affs.c @@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node return 0; } latin1[symlink_size] = 0; - utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1); + utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size); if (!utf8) { grub_free (latin1); @@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_ return 1; } - hashtable = grub_zalloc (data->htsize * sizeof (*hashtable)); + hashtable = grub_calloc (data->htsize, sizeof (*hashtable)); if (!hashtable) return 1; @@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, c len = file.namelen; if (len > sizeof (file.name)) len = sizeof (file.name); - *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); + *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len); if (*label) *grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0'; } Index: grub-2.02/grub-core/fs/btrfs.c =================================================================== --- grub-2.02.orig/grub-core/fs/btrfs.c +++ grub-2.02/grub-core/fs/btrfs.c @@ -404,7 +404,7 @@ lower_bound (struct grub_btrfs_data *dat { desc->allocated = 16; desc->depth = 0; - desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated); + desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0])); if (!desc->data) return grub_errno; } @@ -2063,7 +2063,7 @@ grub_btrfs_embed (grub_device_t device _ *nsectors = 64 * 2 - 1; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) Index: grub-2.02/grub-core/fs/hfs.c =================================================================== --- grub-2.02.orig/grub-core/fs/hfs.c +++ grub-2.02/grub-core/fs/hfs.c @@ -1360,7 +1360,7 @@ grub_hfs_label (grub_device_t device, ch grub_size_t len = data->sblock.volname[0]; if (len > sizeof (data->sblock.volname) - 1) len = sizeof (data->sblock.volname) - 1; - *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1); + *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len); if (*label) macroman_to_utf8 (*label, data->sblock.volname + 1, len + 1, 0); Index: grub-2.02/grub-core/fs/hfsplus.c =================================================================== --- grub-2.02.orig/grub-core/fs/hfsplus.c +++ grub-2.02/grub-core/fs/hfsplus.c @@ -1012,7 +1012,7 @@ grub_hfsplus_label (grub_device_t device return 0; } - *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1); + *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1); if (! *label) return grub_errno; Index: grub-2.02/grub-core/fs/iso9660.c =================================================================== --- grub-2.02.orig/grub-core/fs/iso9660.c +++ grub-2.02/grub-core/fs/iso9660.c @@ -331,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_ int i; grub_uint16_t t[MAX_NAMELEN / 2 + 1]; - p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); + p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); if (! p) return NULL; Index: grub-2.02/grub-core/fs/ntfs.c =================================================================== --- grub-2.02.orig/grub-core/fs/ntfs.c +++ grub-2.02/grub-core/fs/ntfs.c @@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t grub_uint16_t *tmp; grub_size_t i; - buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); - tmp = grub_malloc (len * sizeof (tmp[0])); + buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); + tmp = grub_calloc (len, sizeof (tmp[0])); if (!buf || !tmp) { grub_free (buf); Index: grub-2.02/grub-core/fs/sfs.c =================================================================== --- grub-2.02.orig/grub-core/fs/sfs.c +++ grub-2.02/grub-core/fs/sfs.c @@ -266,7 +266,7 @@ grub_sfs_read_block (grub_fshelp_node_t node->next_extent = node->block; node->cache_size = 0; - node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size); + node->cache = grub_calloc (cache_size, sizeof (node->cache[0])); if (!node->cache) { grub_errno = 0; Index: grub-2.02/grub-core/fs/tar.c =================================================================== --- grub-2.02.orig/grub-core/fs/tar.c +++ grub-2.02/grub-core/fs/tar.c @@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp if (data->linkname_alloc < linksize + 1) { char *n; - n = grub_malloc (2 * (linksize + 1)); + n = grub_calloc (2, linksize + 1); if (!n) return grub_errno; grub_free (data->linkname); Index: grub-2.02/grub-core/fs/udf.c =================================================================== --- grub-2.02.orig/grub-core/fs/udf.c +++ grub-2.02/grub-core/fs/udf.c @@ -836,7 +836,7 @@ read_string (const grub_uint8_t *raw, gr { unsigned i; utf16len = sz - 1; - utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + utf16 = grub_calloc (utf16len, sizeof (utf16[0])); if (!utf16) return NULL; for (i = 0; i < utf16len; i++) @@ -846,7 +846,7 @@ read_string (const grub_uint8_t *raw, gr { unsigned i; utf16len = (sz - 1) / 2; - utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + utf16 = grub_calloc (utf16len, sizeof (utf16[0])); if (!utf16) return NULL; for (i = 0; i < utf16len; i++) Index: grub-2.02/grub-core/fs/zfs/zfs.c =================================================================== --- grub-2.02.orig/grub-core/fs/zfs/zfs.c +++ grub-2.02/grub-core/fs/zfs/zfs.c @@ -3325,7 +3325,7 @@ dnode_get_fullpath (const char *fullpath } subvol->nkeys = 0; zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data); - subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0])); + subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0])); if (!subvol->keyring) { grub_free (fsname); @@ -4336,7 +4336,7 @@ grub_zfs_embed (grub_device_t device __a *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS); if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) Index: grub-2.02/grub-core/gfxmenu/gui_string_util.c =================================================================== --- grub-2.02.orig/grub-core/gfxmenu/gui_string_util.c +++ grub-2.02/grub-core/gfxmenu/gui_string_util.c @@ -55,7 +55,7 @@ canonicalize_path (const char *path) if (*p == '/') components++; - char **path_array = grub_malloc (components * sizeof (*path_array)); + char **path_array = grub_calloc (components, sizeof (*path_array)); if (! path_array) return 0; Index: grub-2.02/grub-core/gfxmenu/widget-box.c =================================================================== --- grub-2.02.orig/grub-core/gfxmenu/widget-box.c +++ grub-2.02/grub-core/gfxmenu/widget-box.c @@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pix box->content_height = 0; box->raw_pixmaps = (struct grub_video_bitmap **) - grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); + grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); box->scaled_pixmaps = (struct grub_video_bitmap **) - grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); + grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); /* Initialize all pixmap pointers to NULL so that proper destruction can be performed if an error is encountered partway through construction. */ Index: grub-2.02/grub-core/io/gzio.c =================================================================== --- grub-2.02.orig/grub-core/io/gzio.c +++ grub-2.02/grub-core/io/gzio.c @@ -542,7 +542,7 @@ huft_build (unsigned *b, /* code lengths z = 1 << j; /* table entries for j-bit table */ /* allocate and link in new table */ - q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft)); + q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft)); if (! q) { if (h) Index: grub-2.02/grub-core/kern/efi/efi.c =================================================================== --- grub-2.02.orig/grub-core/kern/efi/efi.c +++ grub-2.02/grub-core/kern/efi/efi.c @@ -202,7 +202,7 @@ grub_efi_set_variable(const char *var, c len = grub_strlen (var); len16 = len * GRUB_MAX_UTF16_PER_UTF8; - var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); + var16 = grub_calloc (len16 + 1, sizeof (var16[0])); if (!var16) return grub_errno; len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); @@ -237,7 +237,7 @@ grub_efi_get_variable (const char *var, len = grub_strlen (var); len16 = len * GRUB_MAX_UTF16_PER_UTF8; - var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); + var16 = grub_calloc (len16 + 1, sizeof (var16[0])); if (!var16) return NULL; len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); Index: grub-2.02/grub-core/kern/emu/hostdisk.c =================================================================== --- grub-2.02.orig/grub-core/kern/emu/hostdisk.c +++ grub-2.02/grub-core/kern/emu/hostdisk.c @@ -615,7 +615,7 @@ static char * grub_util_path_concat_real (size_t n, int ext, va_list ap) { size_t totlen = 0; - char **l = xmalloc ((n + ext) * sizeof (l[0])); + char **l = xcalloc (n + ext, sizeof (l[0])); char *r, *p, *pi; size_t i; int first = 1; Index: grub-2.02/grub-core/kern/fs.c =================================================================== --- grub-2.02.orig/grub-core/kern/fs.c +++ grub-2.02/grub-core/kern/fs.c @@ -152,7 +152,7 @@ grub_fs_blocklist_open (grub_file_t file while (p); /* Allocate a block list. */ - blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1)); + blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block)); if (! blocks) return 0; Index: grub-2.02/grub-core/kern/misc.c =================================================================== --- grub-2.02.orig/grub-core/kern/misc.c +++ grub-2.02/grub-core/kern/misc.c @@ -694,7 +694,7 @@ parse_printf_args (const char *fmt0, str args->ptr = args->prealloc; else { - args->ptr = grub_malloc (args->count * sizeof (args->ptr[0])); + args->ptr = grub_calloc (args->count, sizeof (args->ptr[0])); if (!args->ptr) { grub_errno = GRUB_ERR_NONE; Index: grub-2.02/grub-core/kern/parser.c =================================================================== --- grub-2.02.orig/grub-core/kern/parser.c +++ grub-2.02/grub-core/kern/parser.c @@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *c return grub_errno; grub_memcpy (args, buffer, bp - buffer); - *argv = grub_malloc (sizeof (char *) * (*argc + 1)); + *argv = grub_calloc (*argc + 1, sizeof (char *)); if (!*argv) { grub_free (args); Index: grub-2.02/grub-core/kern/uboot/uboot.c =================================================================== --- grub-2.02.orig/grub-core/kern/uboot/uboot.c +++ grub-2.02/grub-core/kern/uboot/uboot.c @@ -168,7 +168,7 @@ grub_uboot_dev_enum (void) return num_devices; max_devices = 2; - enum_devices = grub_malloc (sizeof(struct device_info) * max_devices); + enum_devices = grub_calloc (max_devices, sizeof(struct device_info)); if (!enum_devices) return 0; Index: grub-2.02/grub-core/lib/libgcrypt/cipher/ac.c =================================================================== --- grub-2.02.orig/grub-core/lib/libgcrypt/cipher/ac.c +++ grub-2.02/grub-core/lib/libgcrypt/cipher/ac.c @@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mp gcry_mpi_t mpi; char *label; - data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n); + data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new)); if (! data_mpis_new) { err = gcry_error_from_errno (errno); @@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t da } /* Add MPI list. */ - arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1)); + arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list)); if (! arg_list) { err = gcry_error_from_errno (errno); @@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifie /* We build a list of arguments to pass to gcry_sexp_build_array(). */ data_length = _gcry_ac_data_length (data); - arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2)); + arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2); if (! arg_list) { err = gcry_error_from_errno (errno); @@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_hand arg_list_n += 2; /* Allocate list. */ - arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n); + arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list)); if (! arg_list) { err = gcry_error_from_errno (errno); Index: grub-2.02/grub-core/lib/libgcrypt/cipher/primegen.c =================================================================== --- grub-2.02.orig/grub-core/lib/libgcrypt/cipher/primegen.c +++ grub-2.02/grub-core/lib/libgcrypt/cipher/primegen.c @@ -383,7 +383,7 @@ prime_generate_internal (int need_q_fact } /* Allocate an array to track pool usage. */ - pool_in_use = gcry_malloc (n * sizeof *pool_in_use); + pool_in_use = gcry_calloc (n, sizeof *pool_in_use); if (!pool_in_use) { err = gpg_err_code_from_errno (errno); @@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secre if (nbits < 16) log_fatal ("can't generate a prime with less than %d bits\n", 16); - mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods ); + mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods); /* Make nbits fit into gcry_mpi_t implementation. */ val_2 = mpi_alloc_set_ui( 2 ); val_3 = mpi_alloc_set_ui( 3); Index: grub-2.02/grub-core/lib/libgcrypt/cipher/pubkey.c =================================================================== --- grub-2.02.orig/grub-core/lib/libgcrypt/cipher/pubkey.c +++ grub-2.02/grub-core/lib/libgcrypt/cipher/pubkey.c @@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gc * array to a format string, so we have to do it this way :-(. */ /* FIXME: There is now such a format specifier, so we can change the code to be more clear. */ - arg_list = malloc (nelem * sizeof *arg_list); + arg_list = calloc (nelem, sizeof *arg_list); if (!arg_list) { rc = gpg_err_code_from_syserror (); @@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_s } strcpy (p, "))"); - arg_list = malloc (nelem * sizeof *arg_list); + arg_list = calloc (nelem, sizeof *arg_list); if (!arg_list) { rc = gpg_err_code_from_syserror (); Index: grub-2.02/grub-core/lib/priority_queue.c =================================================================== --- grub-2.02.orig/grub-core/lib/priority_queue.c +++ grub-2.02/grub-core/lib/priority_queue.c @@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t els { struct grub_priority_queue *ret; void *els; - els = grub_malloc (elsize * 8); + els = grub_calloc (8, elsize); if (!els) return 0; ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret)); Index: grub-2.02/grub-core/lib/reed_solomon.c =================================================================== --- grub-2.02.orig/grub-core/lib/reed_solomon.c +++ grub-2.02/grub-core/lib/reed_solomon.c @@ -20,6 +20,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#define xcalloc calloc #define xmalloc malloc #define grub_memset memset #define grub_memcpy memcpy @@ -158,11 +159,9 @@ rs_encode (gf_single_t *data, grub_size_ gf_single_t *rs_polynomial; int i, j; gf_single_t *m; - m = xmalloc ((s + rs) * sizeof (gf_single_t)); + m = xcalloc (s + rs, sizeof (gf_single_t)); grub_memcpy (m, data, s * sizeof (gf_single_t)); - grub_memset (m + s, 0, rs * sizeof (gf_single_t)); - rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); - grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); + rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t)); rs_polynomial[rs] = 1; /* Multiply with X - a^r */ for (j = 0; j < rs; j++) Index: grub-2.02/grub-core/lib/relocator.c =================================================================== --- grub-2.02.orig/grub-core/lib/relocator.c +++ grub-2.02/grub-core/lib/relocator.c @@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator * } #endif - eventt = grub_malloc (maxevents * sizeof (events[0])); + eventt = grub_calloc (maxevents, sizeof (events[0])); counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); - events = grub_malloc (maxevents * sizeof (events[0])); + events = grub_calloc (maxevents, sizeof (events[0])); if (!events || !eventt || !counter) { grub_dprintf ("relocator", "events or counter allocation failed %d\n", @@ -963,7 +963,7 @@ malloc_in_range (struct grub_relocator * #endif unsigned cural = 0; int oom = 0; - res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs); + res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0])); if (!res->subchunks) oom = 1; res->nsubchunks = nallocs; @@ -1562,8 +1562,8 @@ grub_relocator_prepare_relocs (struct gr count[(chunk->src & 0xff) + 1]++; } } - from = grub_malloc (nchunks * sizeof (sorted[0])); - to = grub_malloc (nchunks * sizeof (sorted[0])); + from = grub_calloc (nchunks, sizeof (sorted[0])); + to = grub_calloc (nchunks, sizeof (sorted[0])); if (!from || !to) { grub_free (from); Index: grub-2.02/grub-core/loader/arm/linux.c =================================================================== --- grub-2.02.orig/grub-core/loader/arm/linux.c +++ grub-2.02/grub-core/loader/arm/linux.c @@ -79,7 +79,7 @@ linux_prepare_atag (void) /* some place for cmdline, initrd and terminator. */ tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4; - tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t)); + tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t)); if (!tmp_atag) return grub_errno; Index: grub-2.02/grub-core/loader/i386/bsdXX.c =================================================================== --- grub-2.02.orig/grub-core/loader/i386/bsdXX.c +++ grub-2.02/grub-core/loader/i386/bsdXX.c @@ -48,7 +48,7 @@ read_headers (grub_file_t file, const ch if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS)) return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); - *shdr = grub_malloc ((grub_uint32_t) e->e_shnum * e->e_shentsize); + *shdr = grub_calloc (e->e_shnum, e->e_shentsize); if (! *shdr) return grub_errno; Index: grub-2.02/grub-core/loader/i386/xnu.c =================================================================== --- grub-2.02.orig/grub-core/loader/i386/xnu.c +++ grub-2.02/grub-core/loader/i386/xnu.c @@ -295,7 +295,7 @@ grub_xnu_devprop_add_property_utf8 (stru return grub_errno; len = grub_strlen (name); - utf16 = grub_malloc (sizeof (grub_uint16_t) * len); + utf16 = grub_calloc (len, sizeof (grub_uint16_t)); if (!utf16) { grub_free (utf8); @@ -331,7 +331,7 @@ grub_xnu_devprop_add_property_utf16 (str grub_uint16_t *utf16; grub_err_t err; - utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen); + utf16 = grub_calloc (namelen, sizeof (grub_uint16_t)); if (!utf16) return grub_errno; grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen); Index: grub-2.02/grub-core/loader/macho.c =================================================================== --- grub-2.02.orig/grub-core/loader/macho.c +++ grub-2.02/grub-core/loader/macho.c @@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header)) == (grub_off_t) -1) goto fail; - archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); + archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); if (!archs) goto fail; if (grub_file_read (macho->file, archs, Index: grub-2.02/grub-core/loader/multiboot_elfxx.c =================================================================== --- grub-2.02.orig/grub-core/loader/multiboot_elfxx.c +++ grub-2.02/grub-core/loader/multiboot_elfxx.c @@ -200,7 +200,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi { grub_uint8_t *shdr, *shdrptr; - shdr = grub_malloc ((grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize); + shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize); if (!shdr) return grub_errno; Index: grub-2.02/grub-core/loader/xnu.c =================================================================== --- grub-2.02.orig/grub-core/loader/xnu.c +++ grub-2.02/grub-core/loader/xnu.c @@ -791,7 +791,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd _ if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC) { narchs = grub_be_to_cpu32 (head.nfat_arch); - archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); + archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); if (! archs) { grub_file_close (file); Index: grub-2.02/grub-core/mmap/mmap.c =================================================================== --- grub-2.02.orig/grub-core/mmap/mmap.c +++ grub-2.02/grub-core/mmap/mmap.c @@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t ho /* Initialize variables. */ ctx.scanline_events = (struct grub_mmap_scan *) - grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num); + grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2); - present = grub_zalloc (sizeof (present[0]) * current_priority); + present = grub_calloc (current_priority, sizeof (present[0])); if (! ctx.scanline_events || !present) { Index: grub-2.02/grub-core/net/bootp.c =================================================================== --- grub-2.02.orig/grub-core/net/bootp.c +++ grub-2.02/grub-core/net/bootp.c @@ -1252,7 +1252,7 @@ grub_cmd_bootp (struct grub_command *cmd if (ncards == 0) return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found")); - ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); + ifaces = grub_calloc (ncards, sizeof (ifaces[0])); if (!ifaces) return grub_errno; Index: grub-2.02/grub-core/net/dns.c =================================================================== --- grub-2.02.orig/grub-core/net/dns.c +++ grub-2.02/grub-core/net/dns.c @@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __ ptr++; ptr += 4; } - *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) - * grub_be_to_cpu16 (head->ancount)); + *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount), + sizeof ((*data->addresses)[0])); if (!*data->addresses) { grub_errno = GRUB_ERR_NONE; @@ -406,8 +406,8 @@ recv_hook (grub_net_udp_socket_t sock __ dns_cache[h].addresses = 0; dns_cache[h].name = grub_strdup (data->oname); dns_cache[h].naddresses = *data->naddresses; - dns_cache[h].addresses = grub_malloc (*data->naddresses - * sizeof (dns_cache[h].addresses[0])); + dns_cache[h].addresses = grub_calloc (*data->naddresses, + sizeof (dns_cache[h].addresses[0])); dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all; if (!dns_cache[h].addresses || !dns_cache[h].name) { @@ -479,7 +479,7 @@ grub_net_dns_lookup (const char *name, } } - sockets = grub_malloc (sizeof (sockets[0]) * n_servers); + sockets = grub_calloc (n_servers, sizeof (sockets[0])); if (!sockets) return grub_errno; Index: grub-2.02/grub-core/net/net.c =================================================================== --- grub-2.02.orig/grub-core/net/net.c +++ grub-2.02/grub-core/net/net.c @@ -336,8 +336,8 @@ grub_cmd_ipv6_autoconf (struct grub_comm ncards++; } - ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); - slaacs = grub_zalloc (ncards * sizeof (slaacs[0])); + ifaces = grub_calloc (ncards, sizeof (ifaces[0])); + slaacs = grub_calloc (ncards, sizeof (slaacs[0])); if (!ifaces || !slaacs) { grub_free (ifaces); Index: grub-2.02/grub-core/normal/charset.c =================================================================== --- grub-2.02.orig/grub-core/normal/charset.c +++ grub-2.02/grub-core/normal/charset.c @@ -203,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg { grub_size_t msg_len = grub_strlen (msg); - *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); + *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); if (!*unicode_msg) return -1; @@ -488,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub } else { - n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1)); + n = grub_calloc (out->ncomb + 1, sizeof (n[0])); if (!n) { grub_errno = GRUB_ERR_NONE; @@ -842,7 +842,7 @@ grub_bidi_line_logical_to_visual (const } \ } - visual = grub_malloc (sizeof (visual[0]) * logical_len); + visual = grub_calloc (logical_len, sizeof (visual[0])); if (!visual) return -1; @@ -1165,8 +1165,8 @@ grub_bidi_logical_to_visual (const grub_ { const grub_uint32_t *line_start = logical, *ptr; struct grub_unicode_glyph *visual_ptr; - *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0]) - * (logical_len + 2)); + *visual_out = visual_ptr = grub_calloc (logical_len + 2, + 3 * sizeof (visual_ptr[0])); if (!visual_ptr) return -1; for (ptr = logical; ptr <= logical + logical_len; ptr++) Index: grub-2.02/grub-core/normal/cmdline.c =================================================================== --- grub-2.02.orig/grub-core/normal/cmdline.c +++ grub-2.02/grub-core/normal/cmdline.c @@ -41,7 +41,7 @@ grub_err_t grub_set_history (int newsize) { grub_uint32_t **old_hist_lines = hist_lines; - hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); + hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *)); /* Copy the old lines into the new buffer. */ if (old_hist_lines) @@ -114,7 +114,7 @@ static void grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) { grub_free (hist_lines[pos]); - hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); + hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t)); if (!hist_lines[pos]) { grub_print_error (); @@ -349,7 +349,7 @@ grub_cmdline_get (const char *prompt_tra char *ret; unsigned nterms; - buf = grub_malloc (max_len * sizeof (grub_uint32_t)); + buf = grub_calloc (max_len, sizeof (grub_uint32_t)); if (!buf) return 0; @@ -377,7 +377,7 @@ grub_cmdline_get (const char *prompt_tra FOR_ACTIVE_TERM_OUTPUTS(cur) nterms++; - cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); + cl_terms = grub_calloc (nterms, sizeof (cl_terms[0])); if (!cl_terms) { grub_free (buf); @@ -385,7 +385,7 @@ grub_cmdline_get (const char *prompt_tra } cl_term_cur = cl_terms; - unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); + unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); if (!unicode_msg) { grub_free (buf); @@ -495,7 +495,7 @@ grub_cmdline_get (const char *prompt_tra grub_uint32_t *insert; insertlen = grub_strlen (insertu8); - insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); + insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t)); if (!insert) { grub_free (insertu8); @@ -602,7 +602,7 @@ grub_cmdline_get (const char *prompt_tra grub_free (kill_buf); - kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); + kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t)); if (grub_errno) { grub_print_error (); Index: grub-2.02/grub-core/normal/menu_entry.c =================================================================== --- grub-2.02.orig/grub-core/normal/menu_entry.c +++ grub-2.02/grub-core/normal/menu_entry.c @@ -95,8 +95,8 @@ init_line (struct screen *screen, struct { linep->len = 0; linep->max_len = 80; - linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0])); - linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0])); + linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0])); + linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0])); if (! linep->buf || !linep->pos) { grub_free (linep->buf); @@ -287,7 +287,7 @@ update_screen (struct screen *screen, st pos = linep->pos + (term_screen - screen->terms); if (!*pos) - *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos)); + *pos = grub_calloc (linep->len + 1, sizeof (**pos)); if (i == region_start || linep == screen->lines + screen->line || (i > region_start && mode == ALL_LINES)) @@ -471,7 +471,7 @@ insert_string (struct screen *screen, co /* Insert the string. */ current_linep = screen->lines + screen->line; - unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t)); + unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t)); if (!unicode_msg) return 0; @@ -1023,7 +1023,7 @@ complete (struct screen *screen, int con if (completion_buffer.buf) { buflen = grub_strlen (completion_buffer.buf); - ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); + ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t)); if (!ucs4) { @@ -1268,7 +1268,7 @@ grub_menu_entry_run (grub_menu_entry_t e for (i = 0; i < (unsigned) screen->num_lines; i++) { grub_free (screen->lines[i].pos); - screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0])); + screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0])); if (! screen->lines[i].pos) { grub_print_error (); @@ -1278,7 +1278,7 @@ grub_menu_entry_run (grub_menu_entry_t e } } - screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0])); + screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0])); if (!screen->terms) { grub_print_error (); Index: grub-2.02/grub-core/normal/menu_text.c =================================================================== --- grub-2.02.orig/grub-core/normal/menu_text.c +++ grub-2.02/grub-core/normal/menu_text.c @@ -78,7 +78,7 @@ grub_print_message_indented_real (const grub_size_t msg_len = grub_strlen (msg) + 2; int ret = 0; - unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); + unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); if (!unicode_msg) return 0; @@ -231,7 +231,7 @@ print_entry (int y, int highlight, grub_ if ((data->term->flags & GRUB_TERM_DUMB) && title[0] == '\0') return; - unicode_title = grub_malloc (title_len * sizeof (*unicode_title)); + unicode_title = grub_calloc (title_len, sizeof (*unicode_title)); if (! unicode_title) /* XXX How to show this error? */ return; Index: grub-2.02/grub-core/normal/term.c =================================================================== --- grub-2.02.orig/grub-core/normal/term.c +++ grub-2.02/grub-core/normal/term.c @@ -264,7 +264,7 @@ grub_term_save_pos (void) FOR_ACTIVE_TERM_OUTPUTS(cur) cnt++; - ret = grub_malloc (cnt * sizeof (ret[0])); + ret = grub_calloc (cnt, sizeof (ret[0])); if (!ret) return NULL; @@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_ grub_error_push (); - unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t)); + unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t)); grub_error_pop (); Index: grub-2.02/grub-core/osdep/linux/getroot.c =================================================================== --- grub-2.02.orig/grub-core/osdep/linux/getroot.c +++ grub-2.02/grub-core/osdep/linux/getroot.c @@ -176,7 +176,7 @@ grub_util_raid_getmembers (const char *n if (ret != 0) grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno)); - devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); + devicelist = xcalloc (info.nr_disks + 1, sizeof (char *)); for (i = 0, j = 0; j < info.nr_disks; i++) { @@ -249,7 +249,7 @@ grub_find_root_devices_from_btrfs (const return NULL; } - ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0])); + ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0])); for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++) { @@ -508,7 +508,7 @@ grub_find_root_devices_from_mountinfo (c if (relroot) *relroot = NULL; - entries = xmalloc (entry_max * sizeof (*entries)); + entries = xcalloc (entry_max, sizeof (*entries)); again: fp = grub_util_fopen ("/proc/self/mountinfo", "r"); Index: grub-2.02/grub-core/osdep/unix/config.c =================================================================== --- grub-2.02.orig/grub-core/osdep/unix/config.c +++ grub-2.02/grub-core/osdep/unix/config.c @@ -239,7 +239,7 @@ grub_util_load_config (struct grub_util_ argv[0] = "sh"; argv[1] = "-c"; - script = xmalloc (4 * strlen (cfgfile) + 300); + script = xcalloc (4, strlen (cfgfile) + 300); ptr = script; memcpy (ptr, ". '", 3); Index: grub-2.02/grub-core/osdep/windows/getroot.c =================================================================== --- grub-2.02.orig/grub-core/osdep/windows/getroot.c +++ grub-2.02/grub-core/osdep/windows/getroot.c @@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path) for (ptr = path; *ptr; ptr++); allocsize = (ptr - path + 10) * 2; - out = xmalloc (allocsize * sizeof (out[0])); + out = xcalloc (allocsize, sizeof (out[0])); /* When pointing to EFI system partition GetVolumePathName fails for ESP root and returns abberant information for everything Index: grub-2.02/grub-core/osdep/windows/hostdisk.c =================================================================== --- grub-2.02.orig/grub-core/osdep/windows/hostdisk.c +++ grub-2.02/grub-core/osdep/windows/hostdisk.c @@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const c while (1) { - fpa = xmalloc (alloc * sizeof (fpa[0])); + fpa = xcalloc (alloc, sizeof (fpa[0])); len = GetFullPathName (tpath, alloc, fpa, NULL); if (len >= alloc) @@ -387,7 +387,7 @@ grub_util_fd_opendir (const char *name) for (l = 0; name_windows[l]; l++); for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--); l++; - pattern = xmalloc ((l + 3) * sizeof (pattern[0])); + pattern = xcalloc (l + 3, sizeof (pattern[0])); memcpy (pattern, name_windows, l * sizeof (pattern[0])); pattern[l] = '\\'; pattern[l + 1] = '*'; Index: grub-2.02/grub-core/osdep/windows/init.c =================================================================== --- grub-2.02.orig/grub-core/osdep/windows/init.c +++ grub-2.02/grub-core/osdep/windows/init.c @@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribu LPWSTR *targv; targv = CommandLineToArgvW (tcmdline, argc); - *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); + *argv = xcalloc (*argc + 1, sizeof (argv[0])); for (i = 0; i < *argc; i++) (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); Index: grub-2.02/grub-core/osdep/windows/platform.c =================================================================== --- grub-2.02.orig/grub-core/osdep/windows/platform.c +++ grub-2.02/grub-core/osdep/windows/platform.c @@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode")); distrib8_len = grub_strlen (efi_distributor); - distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8 - * sizeof (grub_uint16_t)); + distributor16 = xcalloc (distrib8_len + 1, + GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t)); distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8, (const grub_uint8_t *) efi_distributor, distrib8_len, 0); Index: grub-2.02/grub-core/osdep/windows/relpath.c =================================================================== --- grub-2.02.orig/grub-core/osdep/windows/relpath.c +++ grub-2.02/grub-core/osdep/windows/relpath.c @@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_ro if (dirwindows[0] && dirwindows[1] == ':') offset = 2; } - ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2)); + ret = xcalloc (flen - offset + 2, sizeof (ret[0])); if (dirwindows[offset] != '\\' && dirwindows[offset] != '/' && dirwindows[offset]) Index: grub-2.02/grub-core/partmap/gpt.c =================================================================== --- grub-2.02.orig/grub-core/partmap/gpt.c +++ grub-2.02/grub-core/partmap/gpt.c @@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_dis *nsectors = ctx.len; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) Index: grub-2.02/grub-core/partmap/msdos.c =================================================================== --- grub-2.02.orig/grub-core/partmap/msdos.c +++ grub-2.02/grub-core/partmap/msdos.c @@ -344,7 +344,7 @@ pc_partition_map_embed (struct grub_disk avail_nsectors = *nsectors; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) Index: grub-2.02/grub-core/script/execute.c =================================================================== --- grub-2.02.orig/grub-core/script/execute.c +++ grub-2.02/grub-core/script/execute.c @@ -556,7 +556,7 @@ gettext_append (struct grub_script_argv for (iptr = orig_str; *iptr; iptr++) if (*iptr == '$') dollar_cnt++; - ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt); + ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0])); if (parse_string (orig_str, gettext_save_allow, &ctx, 0)) goto fail; Index: grub-2.02/grub-core/tests/fake_input.c =================================================================== --- grub-2.02.orig/grub-core/tests/fake_input.c +++ grub-2.02/grub-core/tests/fake_input.c @@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int * saved = grub_term_inputs; if (seq) grub_free (seq); - seq = grub_malloc (nseq_in * sizeof (seq[0])); + seq = grub_calloc (nseq_in, sizeof (seq[0])); if (!seq) return; Index: grub-2.02/grub-core/tests/video_checksum.c =================================================================== --- grub-2.02.orig/grub-core/tests/video_checksum.c +++ grub-2.02/grub-core/tests/video_checksum.c @@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char { case 4: { - grub_uint8_t *buffer = xmalloc (mode_info->width * 3); + grub_uint8_t *buffer = xcalloc (3, mode_info->width); grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); @@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char } case 3: { - grub_uint8_t *buffer = xmalloc (mode_info->width * 3); + grub_uint8_t *buffer = xcalloc (3, mode_info->width); grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); @@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char } case 2: { - grub_uint8_t *buffer = xmalloc (mode_info->width * 3); + grub_uint8_t *buffer = xcalloc (3, mode_info->width); grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1); grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1); grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1); Index: grub-2.02/grub-core/video/capture.c =================================================================== --- grub-2.02.orig/grub-core/video/capture.c +++ grub-2.02/grub-core/video/capture.c @@ -89,7 +89,7 @@ grub_video_capture_start (const struct g framebuffer.mode_info = *mode_info; framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); - framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch); + framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch); if (!framebuffer.ptr) return grub_errno; Index: grub-2.02/grub-core/video/emu/sdl.c =================================================================== --- grub-2.02.orig/grub-core/video/emu/sdl.c +++ grub-2.02/grub-core/video/emu/sdl.c @@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int if (start + count > mode_info.number_of_colors) count = mode_info.number_of_colors - start; - tmp = grub_malloc (count * sizeof (tmp[0])); + tmp = grub_calloc (count, sizeof (tmp[0])); for (i = 0; i < count; i++) { tmp[i].r = palette_data[i].r; Index: grub-2.02/grub-core/video/i386/pc/vga.c =================================================================== --- grub-2.02.orig/grub-core/video/i386/pc/vga.c +++ grub-2.02/grub-core/video/i386/pc/vga.c @@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width vga_height = height ? : 480; - framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH); + framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH); framebuffer.front_page = 0; framebuffer.back_page = 0; if (!framebuffer.temporary_buffer) Index: grub-2.02/grub-core/video/readers/png.c =================================================================== --- grub-2.02.orig/grub-core/video/readers/png.c +++ grub-2.02/grub-core/video/readers/png.c @@ -309,7 +309,7 @@ grub_png_decode_image_header (struct gru if (data->is_16bit || data->is_gray || data->is_palette) #endif { - data->image_data = grub_malloc (data->image_height * data->row_bytes); + data->image_data = grub_calloc (data->image_height, data->row_bytes); if (grub_errno) return grub_errno; Index: grub-2.02/include/grub/unicode.h =================================================================== --- grub-2.02.orig/include/grub/unicode.h +++ grub-2.02/include/grub/unicode.h @@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct gru grub_memcpy (out, in, sizeof (*in)); if (in->ncomb > ARRAY_SIZE (out->combining_inline)) { - out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); + out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); if (!out->combining_ptr) { grub_free (out); @@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unic grub_memcpy (out, in, sizeof (*in)); if (in->ncomb > ARRAY_SIZE (out->combining_inline)) { - out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); + out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); if (!out->combining_ptr) return; grub_memcpy (out->combining_ptr, in->combining_ptr, Index: grub-2.02/util/getroot.c =================================================================== --- grub-2.02.orig/util/getroot.c +++ grub-2.02/util/getroot.c @@ -200,7 +200,7 @@ make_device_name (const char *drive) char *ret, *ptr; const char *iptr; - ret = xmalloc (strlen (drive) * 2); + ret = xcalloc (2, strlen (drive)); ptr = ret; for (iptr = drive; *iptr; iptr++) { Index: grub-2.02/util/grub-file.c =================================================================== --- grub-2.02.orig/util/grub-file.c +++ grub-2.02/util/grub-file.c @@ -54,7 +54,7 @@ main (int argc, char *argv[]) grub_util_host_init (&argc, &argv); - argv2 = xmalloc (argc * sizeof (argv2[0])); + argv2 = xcalloc (argc, sizeof (argv2[0])); if (argc == 2 && strcmp (argv[1], "--version") == 0) { Index: grub-2.02/util/grub-fstest.c =================================================================== --- grub-2.02.orig/util/grub-fstest.c +++ grub-2.02/util/grub-fstest.c @@ -650,7 +650,7 @@ argp_parser (int key, char *arg, struct if (args_count < num_disks) { if (args_count == 0) - images = xmalloc (num_disks * sizeof (images[0])); + images = xcalloc (num_disks, sizeof (images[0])); images[args_count] = grub_canonicalize_file_name (arg); args_count++; return 0; @@ -734,7 +734,7 @@ main (int argc, char *argv[]) grub_util_host_init (&argc, &argv); - args = xmalloc (argc * sizeof (args[0])); + args = xcalloc (argc, sizeof (args[0])); argp_parse (&argp, argc, argv, 0, 0, 0); Index: grub-2.02/util/grub-install-common.c =================================================================== --- grub-2.02.orig/util/grub-install-common.c +++ grub-2.02/util/grub-install-common.c @@ -280,7 +280,7 @@ handle_install_list (struct install_list il->n_entries++; } il->n_alloc = il->n_entries + 1; - il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0])); + il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0])); ptr = val; for (ce = il->entries; ; ce++) { Index: grub-2.02/util/grub-install.c =================================================================== --- grub-2.02.orig/util/grub-install.c +++ grub-2.02/util/grub-install.c @@ -642,7 +642,7 @@ device_map_check_duplicates (const char if (! fp) return; - d = xmalloc (alloced * sizeof (d[0])); + d = xcalloc (alloced, sizeof (d[0])); while (fgets (buf, sizeof (buf), fp)) { @@ -1247,7 +1247,7 @@ main (int argc, char *argv[]) ndev++; } - grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); + grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0])); for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, curdrive++) Index: grub-2.02/util/grub-mkrescue.c =================================================================== --- grub-2.02.orig/util/grub-mkrescue.c +++ grub-2.02/util/grub-mkrescue.c @@ -437,8 +437,8 @@ main (int argc, char *argv[]) xorriso = xstrdup ("xorriso"); label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2"); - argp_argv = xmalloc (sizeof (argp_argv[0]) * argc); - xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc); + argp_argv = xcalloc (argc, sizeof (argp_argv[0])); + xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0])); xorriso_tail_argc = 0; /* Program name */ Index: grub-2.02/util/grub-mkstandalone.c =================================================================== --- grub-2.02.orig/util/grub-mkstandalone.c +++ grub-2.02/util/grub-mkstandalone.c @@ -296,7 +296,7 @@ main (int argc, char *argv[]) grub_util_host_init (&argc, &argv); grub_util_disable_fd_syncs (); - files = xmalloc ((argc + 1) * sizeof (files[0])); + files = xcalloc (argc + 1, sizeof (files[0])); argp_parse (&argp, argc, argv, 0, 0, 0); Index: grub-2.02/util/grub-pe2elf.c =================================================================== --- grub-2.02.orig/util/grub-pe2elf.c +++ grub-2.02/util/grub-pe2elf.c @@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char char *pe_strtab = (image + pe_chdr->symtab_offset + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); - section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int)); + section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int)); section_map[0] = 0; - shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0])); + shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0])); idx = 1; idx_reloc = pe_chdr->num_sections + 1; @@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const cha pe_sec = pe_shdr + shdr[i].sh_link; pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset); - rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t)); + rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t)); num_rels = 0; modified = 0; @@ -365,12 +365,10 @@ write_symbol_table (FILE* fp, const char pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset); pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols); - symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) * - sizeof (Elf_Sym)); - memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym)); + symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym)); num_syms = 1; - symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int)); + symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int)); for (i = 0; i < (int) pe_chdr->num_symbols; i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1) Index: grub-2.02/util/grub-probe.c =================================================================== --- grub-2.02.orig/util/grub-probe.c +++ grub-2.02/util/grub-probe.c @@ -305,8 +305,8 @@ probe (const char *path, char **device_n grub_util_pull_device (*curdev); ndev++; } - - drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); + + drives_names = xcalloc (ndev + 1, sizeof (drives_names[0])); for (curdev = device_names, curdrive = drives_names; *curdev; curdev++, curdrive++)
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor