1From 8185711241d73931269f402bb6799f7e2c58f04b Mon Sep 17 00:00:00 2001 2From: Peter Jones <pjones@redhat.com> 3Date: Mon, 15 Jun 2020 12:26:01 -0400 4Subject: [PATCH] calloc: Use calloc() at most places 5MIME-Version: 1.0 6Content-Type: text/plain; charset=UTF-8 7Content-Transfer-Encoding: 8bit 8 9This modifies most of the places we do some form of: 10 11 X = malloc(Y * Z); 12 13to use calloc(Y, Z) instead. 14 15Among other issues, this fixes: 16 - allocation of integer overflow in grub_png_decode_image_header() 17 reported by Chris Coulson, 18 - allocation of integer overflow in luks_recover_key() 19 reported by Chris Coulson, 20 - allocation of integer overflow in grub_lvm_detect() 21 reported by Chris Coulson. 22 23Fixes: CVE-2020-14308 24 25Signed-off-by: Peter Jones <pjones@redhat.com> 26Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 27Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 28--- 29 grub-core/bus/usb/usbhub.c | 8 ++++---- 30 grub-core/commands/efi/lsefisystab.c | 3 ++- 31 grub-core/commands/legacycfg.c | 6 +++--- 32 grub-core/commands/menuentry.c | 2 +- 33 grub-core/commands/nativedisk.c | 2 +- 34 grub-core/commands/parttool.c | 12 +++++++++--- 35 grub-core/commands/regexp.c | 2 +- 36 grub-core/commands/search_wrap.c | 2 +- 37 grub-core/disk/diskfilter.c | 4 ++-- 38 grub-core/disk/ieee1275/ofdisk.c | 2 +- 39 grub-core/disk/ldm.c | 14 +++++++------- 40 grub-core/disk/luks.c | 2 +- 41 grub-core/disk/lvm.c | 8 ++++---- 42 grub-core/disk/xen/xendisk.c | 2 +- 43 grub-core/efiemu/loadcore.c | 2 +- 44 grub-core/efiemu/mm.c | 6 +++--- 45 grub-core/font/font.c | 3 +-- 46 grub-core/fs/affs.c | 6 +++--- 47 grub-core/fs/btrfs.c | 6 +++--- 48 grub-core/fs/hfs.c | 2 +- 49 grub-core/fs/hfsplus.c | 6 +++--- 50 grub-core/fs/iso9660.c | 2 +- 51 grub-core/fs/ntfs.c | 4 ++-- 52 grub-core/fs/sfs.c | 2 +- 53 grub-core/fs/tar.c | 2 +- 54 grub-core/fs/udf.c | 4 ++-- 55 grub-core/fs/zfs/zfs.c | 4 ++-- 56 grub-core/gfxmenu/gui_string_util.c | 2 +- 57 grub-core/gfxmenu/widget-box.c | 4 ++-- 58 grub-core/io/gzio.c | 2 +- 59 grub-core/kern/efi/efi.c | 6 +++--- 60 grub-core/kern/emu/hostdisk.c | 2 +- 61 grub-core/kern/fs.c | 2 +- 62 grub-core/kern/misc.c | 2 +- 63 grub-core/kern/parser.c | 2 +- 64 grub-core/kern/uboot/uboot.c | 2 +- 65 grub-core/lib/libgcrypt/cipher/ac.c | 8 ++++---- 66 grub-core/lib/libgcrypt/cipher/primegen.c | 4 ++-- 67 grub-core/lib/libgcrypt/cipher/pubkey.c | 4 ++-- 68 grub-core/lib/priority_queue.c | 2 +- 69 grub-core/lib/reed_solomon.c | 7 +++---- 70 grub-core/lib/relocator.c | 10 +++++----- 71 grub-core/lib/zstd/fse_decompress.c | 2 +- 72 grub-core/loader/arm/linux.c | 2 +- 73 grub-core/loader/efi/chainloader.c | 2 +- 74 grub-core/loader/i386/bsdXX.c | 2 +- 75 grub-core/loader/i386/xnu.c | 4 ++-- 76 grub-core/loader/macho.c | 2 +- 77 grub-core/loader/multiboot_elfxx.c | 2 +- 78 grub-core/loader/xnu.c | 2 +- 79 grub-core/mmap/mmap.c | 4 ++-- 80 grub-core/net/bootp.c | 2 +- 81 grub-core/net/dns.c | 10 +++++----- 82 grub-core/net/net.c | 4 ++-- 83 grub-core/normal/charset.c | 10 +++++----- 84 grub-core/normal/cmdline.c | 14 +++++++------- 85 grub-core/normal/menu_entry.c | 14 +++++++------- 86 grub-core/normal/menu_text.c | 4 ++-- 87 grub-core/normal/term.c | 4 ++-- 88 grub-core/osdep/linux/getroot.c | 6 +++--- 89 grub-core/osdep/unix/config.c | 2 +- 90 grub-core/osdep/windows/getroot.c | 2 +- 91 grub-core/osdep/windows/hostdisk.c | 4 ++-- 92 grub-core/osdep/windows/init.c | 2 +- 93 grub-core/osdep/windows/platform.c | 4 ++-- 94 grub-core/osdep/windows/relpath.c | 2 +- 95 grub-core/partmap/gpt.c | 2 +- 96 grub-core/partmap/msdos.c | 2 +- 97 grub-core/script/execute.c | 2 +- 98 grub-core/tests/fake_input.c | 2 +- 99 grub-core/tests/video_checksum.c | 6 +++--- 100 grub-core/video/capture.c | 2 +- 101 grub-core/video/emu/sdl.c | 2 +- 102 grub-core/video/i386/pc/vga.c | 2 +- 103 grub-core/video/readers/png.c | 2 +- 104 include/grub/unicode.h | 4 ++-- 105 util/getroot.c | 2 +- 106 util/grub-file.c | 2 +- 107 util/grub-fstest.c | 4 ++-- 108 util/grub-install-common.c | 2 +- 109 util/grub-install.c | 4 ++-- 110 util/grub-mkimagexx.c | 6 ++---- 111 util/grub-mkrescue.c | 4 ++-- 112 util/grub-mkstandalone.c | 2 +- 113 util/grub-pe2elf.c | 12 +++++------- 114 util/grub-probe.c | 4 ++-- 115 86 files changed, 176 insertions(+), 175 deletions(-) 116 117diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c 118index 34a7ff1b5..a06cce302 100644 119--- a/grub-core/bus/usb/usbhub.c 120+++ b/grub-core/bus/usb/usbhub.c 121@@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev) 122 grub_usb_set_configuration (dev, 1); 123 124 dev->nports = hubdesc.portcnt; 125- dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0])); 126- dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0])); 127+ dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0])); 128+ dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0])); 129 if (!dev->children || !dev->ports) 130 { 131 grub_free (dev->children); 132@@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (grub_usb_controller_t controller, void *d 133 134 /* Query the number of ports the root Hub has. */ 135 hub->nports = controller->dev->hubports (controller); 136- hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports); 137- hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports); 138+ hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0])); 139+ hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0])); 140 if (!hub->devices || !hub->ports) 141 { 142 grub_free (hub->devices); 143diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c 144index df1030221..cd81507f5 100644 145--- a/grub-core/commands/efi/lsefisystab.c 146+++ b/grub-core/commands/efi/lsefisystab.c 147@@ -71,7 +71,8 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)), 148 grub_printf ("Vendor: "); 149 150 for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++); 151- vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1); 152+ /* Allocate extra 3 bytes to simplify math. */ 153+ vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1); 154 if (!vendor) 155 return grub_errno; 156 *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor, 157diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c 158index db7a8f002..5e3ec0d5e 100644 159--- a/grub-core/commands/legacycfg.c 160+++ b/grub-core/commands/legacycfg.c 161@@ -314,7 +314,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), 162 if (argc < 2) 163 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); 164 165- cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1)); 166+ cutargs = grub_calloc (argc - 1, sizeof (cutargs[0])); 167 if (!cutargs) 168 return grub_errno; 169 cutargc = argc - 1; 170@@ -436,7 +436,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), 171 { 172 char rbuf[3] = "-r"; 173 bsdargc = cutargc + 2; 174- bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc); 175+ bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0])); 176 if (!bsdargs) 177 { 178 err = grub_errno; 179@@ -559,7 +559,7 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused 180 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), 181 "module"); 182 183- newargs = grub_malloc ((argc + 1) * sizeof (newargs[0])); 184+ newargs = grub_calloc (argc + 1, sizeof (newargs[0])); 185 if (!newargs) 186 return grub_errno; 187 grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0])); 188diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c 189index 2c5363da7..9164df744 100644 190--- a/grub-core/commands/menuentry.c 191+++ b/grub-core/commands/menuentry.c 192@@ -154,7 +154,7 @@ grub_normal_add_menu_entry (int argc, const char **args, 193 goto fail; 194 195 /* Save argc, args to pass as parameters to block arg later. */ 196- menu_args = grub_malloc (sizeof (char*) * (argc + 1)); 197+ menu_args = grub_calloc (argc + 1, sizeof (char *)); 198 if (! menu_args) 199 goto fail; 200 201diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c 202index 699447d11..7c8f97f6a 100644 203--- a/grub-core/commands/nativedisk.c 204+++ b/grub-core/commands/nativedisk.c 205@@ -195,7 +195,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), 206 else 207 path_prefix = prefix; 208 209- mods = grub_malloc (argc * sizeof (mods[0])); 210+ mods = grub_calloc (argc, sizeof (mods[0])); 211 if (!mods) 212 return grub_errno; 213 214diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c 215index 22b46b187..051e31320 100644 216--- a/grub-core/commands/parttool.c 217+++ b/grub-core/commands/parttool.c 218@@ -59,7 +59,13 @@ grub_parttool_register(const char *part_name, 219 for (nargs = 0; args[nargs].name != 0; nargs++); 220 cur->nargs = nargs; 221 cur->args = (struct grub_parttool_argdesc *) 222- grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); 223+ grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc)); 224+ if (!cur->args) 225+ { 226+ grub_free (cur); 227+ curhandle--; 228+ return -1; 229+ } 230 grub_memcpy (cur->args, args, 231 (nargs + 1) * sizeof (struct grub_parttool_argdesc)); 232 233@@ -257,7 +263,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), 234 return err; 235 } 236 237- parsed = (int *) grub_zalloc (argc * sizeof (int)); 238+ parsed = (int *) grub_calloc (argc, sizeof (int)); 239 240 for (i = 1; i < argc; i++) 241 if (! parsed[i]) 242@@ -290,7 +296,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), 243 } 244 ptool = cur; 245 pargs = (struct grub_parttool_args *) 246- grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args)); 247+ grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args)); 248 for (j = i; j < argc; j++) 249 if (! parsed[j]) 250 { 251diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c 252index f00b184c8..4019164f3 100644 253--- a/grub-core/commands/regexp.c 254+++ b/grub-core/commands/regexp.c 255@@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args) 256 if (ret) 257 goto fail; 258 259- matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1)); 260+ matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches)); 261 if (! matches) 262 goto fail; 263 264diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c 265index d7fd26b94..47fc8eb99 100644 266--- a/grub-core/commands/search_wrap.c 267+++ b/grub-core/commands/search_wrap.c 268@@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) 269 for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) 270 nhints++; 271 272- hints = grub_malloc (sizeof (hints[0]) * nhints); 273+ hints = grub_calloc (nhints, sizeof (hints[0])); 274 if (!hints) 275 return grub_errno; 276 j = 0; 277diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c 278index c3b578acf..68ca9e0be 100644 279--- a/grub-core/disk/diskfilter.c 280+++ b/grub-core/disk/diskfilter.c 281@@ -1134,7 +1134,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, 282 array->lvs->segments->node_count = nmemb; 283 array->lvs->segments->raid_member_size = disk_size; 284 array->lvs->segments->nodes 285- = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0])); 286+ = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); 287 array->lvs->segments->stripe_size = stripe_size; 288 for (i = 0; i < nmemb; i++) 289 { 290@@ -1226,7 +1226,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, 291 grub_partition_t p; 292 for (p = disk->partition; p; p = p->parent) 293 s++; 294- pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0])); 295+ pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0])); 296 s = 0; 297 for (p = disk->partition; p; p = p->parent) 298 pv->partmaps[s++] = xstrdup (p->partmap->name); 299diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c 300index f73257e66..03674cb47 100644 301--- a/grub-core/disk/ieee1275/ofdisk.c 302+++ b/grub-core/disk/ieee1275/ofdisk.c 303@@ -297,7 +297,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) 304 /* Power machines documentation specify 672 as maximum SAS disks in 305 one system. Using a slightly larger value to be safe. */ 306 table_size = 768; 307- table = grub_malloc (table_size * sizeof (grub_uint64_t)); 308+ table = grub_calloc (table_size, sizeof (grub_uint64_t)); 309 310 if (!table) 311 { 312diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c 313index 2a22d2d6c..e6323701a 100644 314--- a/grub-core/disk/ldm.c 315+++ b/grub-core/disk/ldm.c 316@@ -323,8 +323,8 @@ make_vg (grub_disk_t disk, 317 lv->segments->type = GRUB_DISKFILTER_MIRROR; 318 lv->segments->node_count = 0; 319 lv->segments->node_alloc = 8; 320- lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes) 321- * lv->segments->node_alloc); 322+ lv->segments->nodes = grub_calloc (lv->segments->node_alloc, 323+ sizeof (*lv->segments->nodes)); 324 if (!lv->segments->nodes) 325 goto fail2; 326 ptr = vblk[i].dynamic; 327@@ -543,8 +543,8 @@ make_vg (grub_disk_t disk, 328 { 329 comp->segment_alloc = 8; 330 comp->segment_count = 0; 331- comp->segments = grub_malloc (sizeof (*comp->segments) 332- * comp->segment_alloc); 333+ comp->segments = grub_calloc (comp->segment_alloc, 334+ sizeof (*comp->segments)); 335 if (!comp->segments) 336 goto fail2; 337 } 338@@ -590,8 +590,8 @@ make_vg (grub_disk_t disk, 339 } 340 comp->segments->node_count = read_int (ptr + 1, *ptr); 341 comp->segments->node_alloc = comp->segments->node_count; 342- comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes) 343- * comp->segments->node_alloc); 344+ comp->segments->nodes = grub_calloc (comp->segments->node_alloc, 345+ sizeof (*comp->segments->nodes)); 346 if (!lv->segments->nodes) 347 goto fail2; 348 } 349@@ -1017,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors, 350 *nsectors = lv->size; 351 if (*nsectors > max_nsectors) 352 *nsectors = max_nsectors; 353- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); 354+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); 355 if (!*sectors) 356 return grub_errno; 357 for (i = 0; i < *nsectors; i++) 358diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c 359index 86c50c612..18b3a8bb1 100644 360--- a/grub-core/disk/luks.c 361+++ b/grub-core/disk/luks.c 362@@ -336,7 +336,7 @@ luks_recover_key (grub_disk_t source, 363 && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) 364 max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); 365 366- split_key = grub_malloc (keysize * max_stripes); 367+ split_key = grub_calloc (keysize, max_stripes); 368 if (!split_key) 369 return grub_errno; 370 371diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c 372index 7b265c780..d1df640b3 100644 373--- a/grub-core/disk/lvm.c 374+++ b/grub-core/disk/lvm.c 375@@ -173,7 +173,7 @@ grub_lvm_detect (grub_disk_t disk, 376 first one. */ 377 378 /* Allocate buffer space for the circular worst-case scenario. */ 379- metadatabuf = grub_malloc (2 * mda_size); 380+ metadatabuf = grub_calloc (2, mda_size); 381 if (! metadatabuf) 382 goto fail; 383 384@@ -426,7 +426,7 @@ grub_lvm_detect (grub_disk_t disk, 385 #endif 386 goto lvs_fail; 387 } 388- lv->segments = grub_zalloc (sizeof (*seg) * lv->segment_count); 389+ lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); 390 seg = lv->segments; 391 392 for (i = 0; i < lv->segment_count; i++) 393@@ -483,8 +483,8 @@ grub_lvm_detect (grub_disk_t disk, 394 if (seg->node_count != 1) 395 seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); 396 397- seg->nodes = grub_zalloc (sizeof (*stripe) 398- * seg->node_count); 399+ seg->nodes = grub_calloc (seg->node_count, 400+ sizeof (*stripe)); 401 stripe = seg->nodes; 402 403 p = grub_strstr (p, "stripes = ["); 404diff --git a/grub-core/disk/xen/xendisk.c b/grub-core/disk/xen/xendisk.c 405index 48476cbbf..d6612eebd 100644 406--- a/grub-core/disk/xen/xendisk.c 407+++ b/grub-core/disk/xen/xendisk.c 408@@ -426,7 +426,7 @@ grub_xendisk_init (void) 409 if (!ctr) 410 return; 411 412- virtdisks = grub_malloc (ctr * sizeof (virtdisks[0])); 413+ virtdisks = grub_calloc (ctr, sizeof (virtdisks[0])); 414 if (!virtdisks) 415 return; 416 if (grub_xenstore_dir ("device/vbd", fill, &ctr)) 417diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c 418index 44085ef81..2b924623f 100644 419--- a/grub-core/efiemu/loadcore.c 420+++ b/grub-core/efiemu/loadcore.c 421@@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e) 422 423 grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize; 424 grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *) 425- grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms); 426+ grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym)); 427 428 /* Relocators */ 429 for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); 430diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c 431index 52a032f7b..9b8e0d0ad 100644 432--- a/grub-core/efiemu/mm.c 433+++ b/grub-core/efiemu/mm.c 434@@ -554,11 +554,11 @@ grub_efiemu_mmap_sort_and_uniq (void) 435 /* Initialize variables*/ 436 grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE); 437 scanline_events = (struct grub_efiemu_mmap_scan *) 438- grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num); 439+ grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2); 440 441 /* Number of chunks can't increase more than by factor of 2 */ 442 result = (grub_efi_memory_descriptor_t *) 443- grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num); 444+ grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2); 445 if (!result || !scanline_events) 446 { 447 grub_free (result); 448@@ -660,7 +660,7 @@ grub_efiemu_mm_do_alloc (void) 449 450 /* Preallocate mmap */ 451 efiemu_mmap = (grub_efi_memory_descriptor_t *) 452- grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t)); 453+ grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t)); 454 if (!efiemu_mmap) 455 { 456 grub_efiemu_unload (); 457diff --git a/grub-core/font/font.c b/grub-core/font/font.c 458index 85a292557..8e118b315 100644 459--- a/grub-core/font/font.c 460+++ b/grub-core/font/font.c 461@@ -293,8 +293,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct 462 font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE; 463 464 /* Allocate the character index array. */ 465- font->char_index = grub_malloc (font->num_chars 466- * sizeof (struct char_index_entry)); 467+ font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry)); 468 if (!font->char_index) 469 return 1; 470 font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); 471diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c 472index 6b6a2bc91..220b3712f 100644 473--- a/grub-core/fs/affs.c 474+++ b/grub-core/fs/affs.c 475@@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node_t node) 476 return 0; 477 } 478 latin1[symlink_size] = 0; 479- utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1); 480+ utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size); 481 if (!utf8) 482 { 483 grub_free (latin1); 484@@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, 485 return 1; 486 } 487 488- hashtable = grub_zalloc (data->htsize * sizeof (*hashtable)); 489+ hashtable = grub_calloc (data->htsize, sizeof (*hashtable)); 490 if (!hashtable) 491 return 1; 492 493@@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, char **label) 494 len = file.namelen; 495 if (len > sizeof (file.name)) 496 len = sizeof (file.name); 497- *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); 498+ *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len); 499 if (*label) 500 *grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0'; 501 } 502diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c 503index 48bd3d04a..11272efc1 100644 504--- a/grub-core/fs/btrfs.c 505+++ b/grub-core/fs/btrfs.c 506@@ -413,7 +413,7 @@ lower_bound (struct grub_btrfs_data *data, 507 { 508 desc->allocated = 16; 509 desc->depth = 0; 510- desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated); 511+ desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0])); 512 if (!desc->data) 513 return grub_errno; 514 } 515@@ -752,7 +752,7 @@ raid56_read_retry (struct grub_btrfs_data *data, 516 grub_err_t ret = GRUB_ERR_OUT_OF_MEMORY; 517 grub_uint64_t i, failed_devices; 518 519- buffers = grub_zalloc (sizeof(*buffers) * nstripes); 520+ buffers = grub_calloc (nstripes, sizeof (*buffers)); 521 if (!buffers) 522 goto cleanup; 523 524@@ -2160,7 +2160,7 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), 525 *nsectors = 64 * 2 - 1; 526 if (*nsectors > max_nsectors) 527 *nsectors = max_nsectors; 528- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); 529+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); 530 if (!*sectors) 531 return grub_errno; 532 for (i = 0; i < *nsectors; i++) 533diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c 534index ac0a40990..3fe842b4d 100644 535--- a/grub-core/fs/hfs.c 536+++ b/grub-core/fs/hfs.c 537@@ -1360,7 +1360,7 @@ grub_hfs_label (grub_device_t device, char **label) 538 grub_size_t len = data->sblock.volname[0]; 539 if (len > sizeof (data->sblock.volname) - 1) 540 len = sizeof (data->sblock.volname) - 1; 541- *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1); 542+ *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len); 543 if (*label) 544 macroman_to_utf8 (*label, data->sblock.volname + 1, 545 len + 1, 0); 546diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c 547index 54786bb1c..dae43becc 100644 548--- a/grub-core/fs/hfsplus.c 549+++ b/grub-core/fs/hfsplus.c 550@@ -720,7 +720,7 @@ list_nodes (void *record, void *hook_arg) 551 if (! filename) 552 return 0; 553 554- keyname = grub_malloc (grub_be_to_cpu16 (catkey->namelen) * sizeof (*keyname)); 555+ keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname)); 556 if (!keyname) 557 { 558 grub_free (filename); 559@@ -1007,7 +1007,7 @@ grub_hfsplus_label (grub_device_t device, char **label) 560 grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); 561 562 label_len = grub_be_to_cpu16 (catkey->namelen); 563- label_name = grub_malloc (label_len * sizeof (*label_name)); 564+ label_name = grub_calloc (label_len, sizeof (*label_name)); 565 if (!label_name) 566 { 567 grub_free (node); 568@@ -1029,7 +1029,7 @@ grub_hfsplus_label (grub_device_t device, char **label) 569 } 570 } 571 572- *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1); 573+ *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1); 574 if (! *label) 575 { 576 grub_free (label_name); 577diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c 578index 49c0c632b..4f1b52a55 100644 579--- a/grub-core/fs/iso9660.c 580+++ b/grub-core/fs/iso9660.c 581@@ -331,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_t *us, int len) 582 int i; 583 grub_uint16_t t[MAX_NAMELEN / 2 + 1]; 584 585- p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); 586+ p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); 587 if (! p) 588 return NULL; 589 590diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c 591index fc4e1f678..2f34f76da 100644 592--- a/grub-core/fs/ntfs.c 593+++ b/grub-core/fs/ntfs.c 594@@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t len) 595 grub_uint16_t *tmp; 596 grub_size_t i; 597 598- buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); 599- tmp = grub_malloc (len * sizeof (tmp[0])); 600+ buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); 601+ tmp = grub_calloc (len, sizeof (tmp[0])); 602 if (!buf || !tmp) 603 { 604 grub_free (buf); 605diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c 606index 50c1fe72f..90f7fb379 100644 607--- a/grub-core/fs/sfs.c 608+++ b/grub-core/fs/sfs.c 609@@ -266,7 +266,7 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) 610 node->next_extent = node->block; 611 node->cache_size = 0; 612 613- node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size); 614+ node->cache = grub_calloc (cache_size, sizeof (node->cache[0])); 615 if (!node->cache) 616 { 617 grub_errno = 0; 618diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c 619index 7d63e0c99..c551ed6b5 100644 620--- a/grub-core/fs/tar.c 621+++ b/grub-core/fs/tar.c 622@@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, 623 if (data->linkname_alloc < linksize + 1) 624 { 625 char *n; 626- n = grub_malloc (2 * (linksize + 1)); 627+ n = grub_calloc (2, linksize + 1); 628 if (!n) 629 return grub_errno; 630 grub_free (data->linkname); 631diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c 632index dc8b6e2d1..a83761674 100644 633--- a/grub-core/fs/udf.c 634+++ b/grub-core/fs/udf.c 635@@ -873,7 +873,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) 636 { 637 unsigned i; 638 utf16len = sz - 1; 639- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); 640+ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); 641 if (!utf16) 642 return NULL; 643 for (i = 0; i < utf16len; i++) 644@@ -883,7 +883,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) 645 { 646 unsigned i; 647 utf16len = (sz - 1) / 2; 648- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); 649+ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); 650 if (!utf16) 651 return NULL; 652 for (i = 0; i < utf16len; i++) 653diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c 654index 2f72e42bf..381dde556 100644 655--- a/grub-core/fs/zfs/zfs.c 656+++ b/grub-core/fs/zfs/zfs.c 657@@ -3325,7 +3325,7 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, 658 } 659 subvol->nkeys = 0; 660 zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data); 661- subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0])); 662+ subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0])); 663 if (!subvol->keyring) 664 { 665 grub_free (fsname); 666@@ -4336,7 +4336,7 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)), 667 *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS); 668 if (*nsectors > max_nsectors) 669 *nsectors = max_nsectors; 670- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); 671+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); 672 if (!*sectors) 673 return grub_errno; 674 for (i = 0; i < *nsectors; i++) 675diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c 676index a9a415e31..ba1e1eab3 100644 677--- a/grub-core/gfxmenu/gui_string_util.c 678+++ b/grub-core/gfxmenu/gui_string_util.c 679@@ -55,7 +55,7 @@ canonicalize_path (const char *path) 680 if (*p == '/') 681 components++; 682 683- char **path_array = grub_malloc (components * sizeof (*path_array)); 684+ char **path_array = grub_calloc (components, sizeof (*path_array)); 685 if (! path_array) 686 return 0; 687 688diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c 689index b60602889..470597ded 100644 690--- a/grub-core/gfxmenu/widget-box.c 691+++ b/grub-core/gfxmenu/widget-box.c 692@@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix, 693 box->content_height = 0; 694 box->raw_pixmaps = 695 (struct grub_video_bitmap **) 696- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); 697+ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); 698 box->scaled_pixmaps = 699 (struct grub_video_bitmap **) 700- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); 701+ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); 702 703 /* Initialize all pixmap pointers to NULL so that proper destruction can 704 be performed if an error is encountered partway through construction. */ 705diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c 706index 6208a9763..43d98a7bd 100644 707--- a/grub-core/io/gzio.c 708+++ b/grub-core/io/gzio.c 709@@ -554,7 +554,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ 710 z = 1 << j; /* table entries for j-bit table */ 711 712 /* allocate and link in new table */ 713- q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft)); 714+ q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft)); 715 if (! q) 716 { 717 if (h) 718diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c 719index 6e1ceb905..dc31caa21 100644 720--- a/grub-core/kern/efi/efi.c 721+++ b/grub-core/kern/efi/efi.c 722@@ -202,7 +202,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, 723 724 len = grub_strlen (var); 725 len16 = len * GRUB_MAX_UTF16_PER_UTF8; 726- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); 727+ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); 728 if (!var16) 729 return grub_errno; 730 len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); 731@@ -237,7 +237,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, 732 733 len = grub_strlen (var); 734 len16 = len * GRUB_MAX_UTF16_PER_UTF8; 735- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); 736+ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); 737 if (!var16) 738 return NULL; 739 len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); 740@@ -383,7 +383,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) 741 while (len > 0 && fp->path_name[len - 1] == 0) 742 len--; 743 744- dup_name = grub_malloc (len * sizeof (*dup_name)); 745+ dup_name = grub_calloc (len, sizeof (*dup_name)); 746 if (!dup_name) 747 { 748 grub_free (name); 749diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c 750index e9ec680cd..d975265b2 100644 751--- a/grub-core/kern/emu/hostdisk.c 752+++ b/grub-core/kern/emu/hostdisk.c 753@@ -615,7 +615,7 @@ static char * 754 grub_util_path_concat_real (size_t n, int ext, va_list ap) 755 { 756 size_t totlen = 0; 757- char **l = xmalloc ((n + ext) * sizeof (l[0])); 758+ char **l = xcalloc (n + ext, sizeof (l[0])); 759 char *r, *p, *pi; 760 size_t i; 761 int first = 1; 762diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c 763index 2b85f4950..f90be6566 100644 764--- a/grub-core/kern/fs.c 765+++ b/grub-core/kern/fs.c 766@@ -151,7 +151,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name) 767 while (p); 768 769 /* Allocate a block list. */ 770- blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1)); 771+ blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block)); 772 if (! blocks) 773 return 0; 774 775diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c 776index 3b633d51f..a7abd367a 100644 777--- a/grub-core/kern/misc.c 778+++ b/grub-core/kern/misc.c 779@@ -690,7 +690,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, 780 args->ptr = args->prealloc; 781 else 782 { 783- args->ptr = grub_malloc (args->count * sizeof (args->ptr[0])); 784+ args->ptr = grub_calloc (args->count, sizeof (args->ptr[0])); 785 if (!args->ptr) 786 { 787 grub_errno = GRUB_ERR_NONE; 788diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c 789index 78175aac2..619db3122 100644 790--- a/grub-core/kern/parser.c 791+++ b/grub-core/kern/parser.c 792@@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *cmdline, 793 return grub_errno; 794 grub_memcpy (args, buffer, bp - buffer); 795 796- *argv = grub_malloc (sizeof (char *) * (*argc + 1)); 797+ *argv = grub_calloc (*argc + 1, sizeof (char *)); 798 if (!*argv) 799 { 800 grub_free (args); 801diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c 802index be4816fe6..aac8f9ae1 100644 803--- a/grub-core/kern/uboot/uboot.c 804+++ b/grub-core/kern/uboot/uboot.c 805@@ -133,7 +133,7 @@ grub_uboot_dev_enum (void) 806 return num_devices; 807 808 max_devices = 2; 809- enum_devices = grub_malloc (sizeof(struct device_info) * max_devices); 810+ enum_devices = grub_calloc (max_devices, sizeof(struct device_info)); 811 if (!enum_devices) 812 return 0; 813 814diff --git a/grub-core/lib/libgcrypt/cipher/ac.c b/grub-core/lib/libgcrypt/cipher/ac.c 815index f5e946a2d..63f6fcd11 100644 816--- a/grub-core/lib/libgcrypt/cipher/ac.c 817+++ b/grub-core/lib/libgcrypt/cipher/ac.c 818@@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mpis, unsigned int data_mpis_n, 819 gcry_mpi_t mpi; 820 char *label; 821 822- data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n); 823+ data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new)); 824 if (! data_mpis_new) 825 { 826 err = gcry_error_from_errno (errno); 827@@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, 828 } 829 830 /* Add MPI list. */ 831- arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1)); 832+ arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list)); 833 if (! arg_list) 834 { 835 err = gcry_error_from_errno (errno); 836@@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifier, int include_flags, 837 /* We build a list of arguments to pass to 838 gcry_sexp_build_array(). */ 839 data_length = _gcry_ac_data_length (data); 840- arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2)); 841+ arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2); 842 if (! arg_list) 843 { 844 err = gcry_error_from_errno (errno); 845@@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits, 846 arg_list_n += 2; 847 848 /* Allocate list. */ 849- arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n); 850+ arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list)); 851 if (! arg_list) 852 { 853 err = gcry_error_from_errno (errno); 854diff --git a/grub-core/lib/libgcrypt/cipher/primegen.c b/grub-core/lib/libgcrypt/cipher/primegen.c 855index 2788e349f..b12e79b19 100644 856--- a/grub-core/lib/libgcrypt/cipher/primegen.c 857+++ b/grub-core/lib/libgcrypt/cipher/primegen.c 858@@ -383,7 +383,7 @@ prime_generate_internal (int need_q_factor, 859 } 860 861 /* Allocate an array to track pool usage. */ 862- pool_in_use = gcry_malloc (n * sizeof *pool_in_use); 863+ pool_in_use = gcry_calloc (n, sizeof *pool_in_use); 864 if (!pool_in_use) 865 { 866 err = gpg_err_code_from_errno (errno); 867@@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secret, int randomlevel, 868 if (nbits < 16) 869 log_fatal ("can't generate a prime with less than %d bits\n", 16); 870 871- mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods ); 872+ mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods); 873 /* Make nbits fit into gcry_mpi_t implementation. */ 874 val_2 = mpi_alloc_set_ui( 2 ); 875 val_3 = mpi_alloc_set_ui( 3); 876diff --git a/grub-core/lib/libgcrypt/cipher/pubkey.c b/grub-core/lib/libgcrypt/cipher/pubkey.c 877index 910982141..ca087ad75 100644 878--- a/grub-core/lib/libgcrypt/cipher/pubkey.c 879+++ b/grub-core/lib/libgcrypt/cipher/pubkey.c 880@@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) 881 * array to a format string, so we have to do it this way :-(. */ 882 /* FIXME: There is now such a format specifier, so we can 883 change the code to be more clear. */ 884- arg_list = malloc (nelem * sizeof *arg_list); 885+ arg_list = calloc (nelem, sizeof *arg_list); 886 if (!arg_list) 887 { 888 rc = gpg_err_code_from_syserror (); 889@@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) 890 } 891 strcpy (p, "))"); 892 893- arg_list = malloc (nelem * sizeof *arg_list); 894+ arg_list = calloc (nelem, sizeof *arg_list); 895 if (!arg_list) 896 { 897 rc = gpg_err_code_from_syserror (); 898diff --git a/grub-core/lib/priority_queue.c b/grub-core/lib/priority_queue.c 899index 659be0b7f..7d5e7c05a 100644 900--- a/grub-core/lib/priority_queue.c 901+++ b/grub-core/lib/priority_queue.c 902@@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t elsize, 903 { 904 struct grub_priority_queue *ret; 905 void *els; 906- els = grub_malloc (elsize * 8); 907+ els = grub_calloc (8, elsize); 908 if (!els) 909 return 0; 910 ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret)); 911diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c 912index ee9fa7b4f..467305b46 100644 913--- a/grub-core/lib/reed_solomon.c 914+++ b/grub-core/lib/reed_solomon.c 915@@ -20,6 +20,7 @@ 916 #include <stdio.h> 917 #include <string.h> 918 #include <stdlib.h> 919+#define xcalloc calloc 920 #define xmalloc malloc 921 #define grub_memset memset 922 #define grub_memcpy memcpy 923@@ -158,11 +159,9 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) 924 gf_single_t *rs_polynomial; 925 int i, j; 926 gf_single_t *m; 927- m = xmalloc ((s + rs) * sizeof (gf_single_t)); 928+ m = xcalloc (s + rs, sizeof (gf_single_t)); 929 grub_memcpy (m, data, s * sizeof (gf_single_t)); 930- grub_memset (m + s, 0, rs * sizeof (gf_single_t)); 931- rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); 932- grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); 933+ rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t)); 934 rs_polynomial[rs] = 1; 935 /* Multiply with X - a^r */ 936 for (j = 0; j < rs; j++) 937diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c 938index ea3ebc719..5847aac36 100644 939--- a/grub-core/lib/relocator.c 940+++ b/grub-core/lib/relocator.c 941@@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel, 942 } 943 #endif 944 945- eventt = grub_malloc (maxevents * sizeof (events[0])); 946+ eventt = grub_calloc (maxevents, sizeof (events[0])); 947 counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); 948- events = grub_malloc (maxevents * sizeof (events[0])); 949+ events = grub_calloc (maxevents, sizeof (events[0])); 950 if (!events || !eventt || !counter) 951 { 952 grub_dprintf ("relocator", "events or counter allocation failed %d\n", 953@@ -963,7 +963,7 @@ malloc_in_range (struct grub_relocator *rel, 954 #endif 955 unsigned cural = 0; 956 int oom = 0; 957- res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs); 958+ res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0])); 959 if (!res->subchunks) 960 oom = 1; 961 res->nsubchunks = nallocs; 962@@ -1562,8 +1562,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr, 963 count[(chunk->src & 0xff) + 1]++; 964 } 965 } 966- from = grub_malloc (nchunks * sizeof (sorted[0])); 967- to = grub_malloc (nchunks * sizeof (sorted[0])); 968+ from = grub_calloc (nchunks, sizeof (sorted[0])); 969+ to = grub_calloc (nchunks, sizeof (sorted[0])); 970 if (!from || !to) 971 { 972 grub_free (from); 973diff --git a/grub-core/lib/zstd/fse_decompress.c b/grub-core/lib/zstd/fse_decompress.c 974index 72bbead5b..2227b84bc 100644 975--- a/grub-core/lib/zstd/fse_decompress.c 976+++ b/grub-core/lib/zstd/fse_decompress.c 977@@ -82,7 +82,7 @@ 978 FSE_DTable* FSE_createDTable (unsigned tableLog) 979 { 980 if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; 981- return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) ); 982+ return (FSE_DTable*)calloc( FSE_DTABLE_SIZE_U32(tableLog), sizeof (U32) ); 983 } 984 985 void FSE_freeDTable (FSE_DTable* dt) 986diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c 987index 51684914c..d70c17486 100644 988--- a/grub-core/loader/arm/linux.c 989+++ b/grub-core/loader/arm/linux.c 990@@ -78,7 +78,7 @@ linux_prepare_atag (void *target_atag) 991 992 /* some place for cmdline, initrd and terminator. */ 993 tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4; 994- tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t)); 995+ tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t)); 996 if (!tmp_atag) 997 return grub_errno; 998 999diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c 1000index cd92ea3f2..daf8c6b54 100644 1001--- a/grub-core/loader/efi/chainloader.c 1002+++ b/grub-core/loader/efi/chainloader.c 1003@@ -116,7 +116,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, 1004 fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; 1005 fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; 1006 1007- path_name = grub_malloc (len * GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); 1008+ path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); 1009 if (!path_name) 1010 return; 1011 1012diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c 1013index af6741d15..a8d8bf7da 100644 1014--- a/grub-core/loader/i386/bsdXX.c 1015+++ b/grub-core/loader/i386/bsdXX.c 1016@@ -48,7 +48,7 @@ read_headers (grub_file_t file, const char *filename, Elf_Ehdr *e, char **shdr) 1017 if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS)) 1018 return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); 1019 1020- *shdr = grub_malloc ((grub_uint32_t) e->e_shnum * e->e_shentsize); 1021+ *shdr = grub_calloc (e->e_shnum, e->e_shentsize); 1022 if (! *shdr) 1023 return grub_errno; 1024 1025diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c 1026index e64ed08f5..b7d176b5d 100644 1027--- a/grub-core/loader/i386/xnu.c 1028+++ b/grub-core/loader/i386/xnu.c 1029@@ -295,7 +295,7 @@ grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *d 1030 return grub_errno; 1031 1032 len = grub_strlen (name); 1033- utf16 = grub_malloc (sizeof (grub_uint16_t) * len); 1034+ utf16 = grub_calloc (len, sizeof (grub_uint16_t)); 1035 if (!utf16) 1036 { 1037 grub_free (utf8); 1038@@ -331,7 +331,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor * 1039 grub_uint16_t *utf16; 1040 grub_err_t err; 1041 1042- utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen); 1043+ utf16 = grub_calloc (namelen, sizeof (grub_uint16_t)); 1044 if (!utf16) 1045 return grub_errno; 1046 grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen); 1047diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c 1048index 085f9c689..05710c48e 100644 1049--- a/grub-core/loader/macho.c 1050+++ b/grub-core/loader/macho.c 1051@@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const char *filename, int is_64bit) 1052 if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header)) 1053 == (grub_off_t) -1) 1054 goto fail; 1055- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); 1056+ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); 1057 if (!archs) 1058 goto fail; 1059 if (grub_file_read (macho->file, archs, 1060diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c 1061index 70cd1db51..cc6853692 100644 1062--- a/grub-core/loader/multiboot_elfxx.c 1063+++ b/grub-core/loader/multiboot_elfxx.c 1064@@ -217,7 +217,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) 1065 { 1066 grub_uint8_t *shdr, *shdrptr; 1067 1068- shdr = grub_malloc ((grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize); 1069+ shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize); 1070 if (!shdr) 1071 return grub_errno; 1072 1073diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c 1074index 7f74d1d6f..77d7060e1 100644 1075--- a/grub-core/loader/xnu.c 1076+++ b/grub-core/loader/xnu.c 1077@@ -800,7 +800,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), 1078 if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC) 1079 { 1080 narchs = grub_be_to_cpu32 (head.nfat_arch); 1081- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); 1082+ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); 1083 if (! archs) 1084 { 1085 grub_file_close (file); 1086diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c 1087index 6a31cbae3..57b4e9a72 100644 1088--- a/grub-core/mmap/mmap.c 1089+++ b/grub-core/mmap/mmap.c 1090@@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) 1091 1092 /* Initialize variables. */ 1093 ctx.scanline_events = (struct grub_mmap_scan *) 1094- grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num); 1095+ grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2); 1096 1097- present = grub_zalloc (sizeof (present[0]) * current_priority); 1098+ present = grub_calloc (current_priority, sizeof (present[0])); 1099 1100 if (! ctx.scanline_events || !present) 1101 { 1102diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c 1103index 04cfbb045..653957200 100644 1104--- a/grub-core/net/bootp.c 1105+++ b/grub-core/net/bootp.c 1106@@ -766,7 +766,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), 1107 if (ncards == 0) 1108 return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found")); 1109 1110- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); 1111+ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); 1112 if (!ifaces) 1113 return grub_errno; 1114 1115diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c 1116index 5d9afe093..e332d5eb4 100644 1117--- a/grub-core/net/dns.c 1118+++ b/grub-core/net/dns.c 1119@@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), 1120 ptr++; 1121 ptr += 4; 1122 } 1123- *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) 1124- * grub_be_to_cpu16 (head->ancount)); 1125+ *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount), 1126+ sizeof ((*data->addresses)[0])); 1127 if (!*data->addresses) 1128 { 1129 grub_errno = GRUB_ERR_NONE; 1130@@ -406,8 +406,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), 1131 dns_cache[h].addresses = 0; 1132 dns_cache[h].name = grub_strdup (data->oname); 1133 dns_cache[h].naddresses = *data->naddresses; 1134- dns_cache[h].addresses = grub_malloc (*data->naddresses 1135- * sizeof (dns_cache[h].addresses[0])); 1136+ dns_cache[h].addresses = grub_calloc (*data->naddresses, 1137+ sizeof (dns_cache[h].addresses[0])); 1138 dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all; 1139 if (!dns_cache[h].addresses || !dns_cache[h].name) 1140 { 1141@@ -479,7 +479,7 @@ grub_net_dns_lookup (const char *name, 1142 } 1143 } 1144 1145- sockets = grub_malloc (sizeof (sockets[0]) * n_servers); 1146+ sockets = grub_calloc (n_servers, sizeof (sockets[0])); 1147 if (!sockets) 1148 return grub_errno; 1149 1150diff --git a/grub-core/net/net.c b/grub-core/net/net.c 1151index d5d726a31..38f19dfc9 100644 1152--- a/grub-core/net/net.c 1153+++ b/grub-core/net/net.c 1154@@ -333,8 +333,8 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)), 1155 ncards++; 1156 } 1157 1158- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); 1159- slaacs = grub_zalloc (ncards * sizeof (slaacs[0])); 1160+ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); 1161+ slaacs = grub_calloc (ncards, sizeof (slaacs[0])); 1162 if (!ifaces || !slaacs) 1163 { 1164 grub_free (ifaces); 1165diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c 1166index b0ab47d73..d57fb72fa 100644 1167--- a/grub-core/normal/charset.c 1168+++ b/grub-core/normal/charset.c 1169@@ -203,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, 1170 { 1171 grub_size_t msg_len = grub_strlen (msg); 1172 1173- *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); 1174+ *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); 1175 1176 if (!*unicode_msg) 1177 return -1; 1178@@ -488,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, 1179 } 1180 else 1181 { 1182- n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1)); 1183+ n = grub_calloc (out->ncomb + 1, sizeof (n[0])); 1184 if (!n) 1185 { 1186 grub_errno = GRUB_ERR_NONE; 1187@@ -842,7 +842,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, 1188 } \ 1189 } 1190 1191- visual = grub_malloc (sizeof (visual[0]) * logical_len); 1192+ visual = grub_calloc (logical_len, sizeof (visual[0])); 1193 if (!visual) 1194 return -1; 1195 1196@@ -1165,8 +1165,8 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, 1197 { 1198 const grub_uint32_t *line_start = logical, *ptr; 1199 struct grub_unicode_glyph *visual_ptr; 1200- *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0]) 1201- * (logical_len + 2)); 1202+ *visual_out = visual_ptr = grub_calloc (logical_len + 2, 1203+ 3 * sizeof (visual_ptr[0])); 1204 if (!visual_ptr) 1205 return -1; 1206 for (ptr = logical; ptr <= logical + logical_len; ptr++) 1207diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c 1208index c037d5050..c57242e2e 100644 1209--- a/grub-core/normal/cmdline.c 1210+++ b/grub-core/normal/cmdline.c 1211@@ -41,7 +41,7 @@ grub_err_t 1212 grub_set_history (int newsize) 1213 { 1214 grub_uint32_t **old_hist_lines = hist_lines; 1215- hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); 1216+ hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *)); 1217 1218 /* Copy the old lines into the new buffer. */ 1219 if (old_hist_lines) 1220@@ -114,7 +114,7 @@ static void 1221 grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) 1222 { 1223 grub_free (hist_lines[pos]); 1224- hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); 1225+ hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t)); 1226 if (!hist_lines[pos]) 1227 { 1228 grub_print_error (); 1229@@ -349,7 +349,7 @@ grub_cmdline_get (const char *prompt_translated) 1230 char *ret; 1231 unsigned nterms; 1232 1233- buf = grub_malloc (max_len * sizeof (grub_uint32_t)); 1234+ buf = grub_calloc (max_len, sizeof (grub_uint32_t)); 1235 if (!buf) 1236 return 0; 1237 1238@@ -377,7 +377,7 @@ grub_cmdline_get (const char *prompt_translated) 1239 FOR_ACTIVE_TERM_OUTPUTS(cur) 1240 nterms++; 1241 1242- cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); 1243+ cl_terms = grub_calloc (nterms, sizeof (cl_terms[0])); 1244 if (!cl_terms) 1245 { 1246 grub_free (buf); 1247@@ -385,7 +385,7 @@ grub_cmdline_get (const char *prompt_translated) 1248 } 1249 cl_term_cur = cl_terms; 1250 1251- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); 1252+ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); 1253 if (!unicode_msg) 1254 { 1255 grub_free (buf); 1256@@ -495,7 +495,7 @@ grub_cmdline_get (const char *prompt_translated) 1257 grub_uint32_t *insert; 1258 1259 insertlen = grub_strlen (insertu8); 1260- insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); 1261+ insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t)); 1262 if (!insert) 1263 { 1264 grub_free (insertu8); 1265@@ -602,7 +602,7 @@ grub_cmdline_get (const char *prompt_translated) 1266 1267 grub_free (kill_buf); 1268 1269- kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); 1270+ kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t)); 1271 if (grub_errno) 1272 { 1273 grub_print_error (); 1274diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c 1275index cdf3590a3..1993995be 100644 1276--- a/grub-core/normal/menu_entry.c 1277+++ b/grub-core/normal/menu_entry.c 1278@@ -95,8 +95,8 @@ init_line (struct screen *screen, struct line *linep) 1279 { 1280 linep->len = 0; 1281 linep->max_len = 80; 1282- linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0])); 1283- linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0])); 1284+ linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0])); 1285+ linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0])); 1286 if (! linep->buf || !linep->pos) 1287 { 1288 grub_free (linep->buf); 1289@@ -287,7 +287,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, 1290 pos = linep->pos + (term_screen - screen->terms); 1291 1292 if (!*pos) 1293- *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos)); 1294+ *pos = grub_calloc (linep->len + 1, sizeof (**pos)); 1295 1296 if (i == region_start || linep == screen->lines + screen->line 1297 || (i > region_start && mode == ALL_LINES)) 1298@@ -471,7 +471,7 @@ insert_string (struct screen *screen, const char *s, int update) 1299 1300 /* Insert the string. */ 1301 current_linep = screen->lines + screen->line; 1302- unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t)); 1303+ unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t)); 1304 1305 if (!unicode_msg) 1306 return 0; 1307@@ -1023,7 +1023,7 @@ complete (struct screen *screen, int continuous, int update) 1308 if (completion_buffer.buf) 1309 { 1310 buflen = grub_strlen (completion_buffer.buf); 1311- ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); 1312+ ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t)); 1313 1314 if (!ucs4) 1315 { 1316@@ -1268,7 +1268,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) 1317 for (i = 0; i < (unsigned) screen->num_lines; i++) 1318 { 1319 grub_free (screen->lines[i].pos); 1320- screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0])); 1321+ screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0])); 1322 if (! screen->lines[i].pos) 1323 { 1324 grub_print_error (); 1325@@ -1278,7 +1278,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) 1326 } 1327 } 1328 1329- screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0])); 1330+ screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0])); 1331 if (!screen->terms) 1332 { 1333 grub_print_error (); 1334diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c 1335index e22bb91f6..18240e76c 100644 1336--- a/grub-core/normal/menu_text.c 1337+++ b/grub-core/normal/menu_text.c 1338@@ -78,7 +78,7 @@ grub_print_message_indented_real (const char *msg, int margin_left, 1339 grub_size_t msg_len = grub_strlen (msg) + 2; 1340 int ret = 0; 1341 1342- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); 1343+ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); 1344 1345 if (!unicode_msg) 1346 return 0; 1347@@ -211,7 +211,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, 1348 1349 title = entry ? entry->title : ""; 1350 title_len = grub_strlen (title); 1351- unicode_title = grub_malloc (title_len * sizeof (*unicode_title)); 1352+ unicode_title = grub_calloc (title_len, sizeof (*unicode_title)); 1353 if (! unicode_title) 1354 /* XXX How to show this error? */ 1355 return; 1356diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c 1357index a1e5c5a0d..cc8c173b6 100644 1358--- a/grub-core/normal/term.c 1359+++ b/grub-core/normal/term.c 1360@@ -264,7 +264,7 @@ grub_term_save_pos (void) 1361 FOR_ACTIVE_TERM_OUTPUTS(cur) 1362 cnt++; 1363 1364- ret = grub_malloc (cnt * sizeof (ret[0])); 1365+ ret = grub_calloc (cnt, sizeof (ret[0])); 1366 if (!ret) 1367 return NULL; 1368 1369@@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_t msg_len) 1370 1371 grub_error_push (); 1372 1373- unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t)); 1374+ unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t)); 1375 1376 grub_error_pop (); 1377 1378diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c 1379index 90d92d3ad..5b41ad022 100644 1380--- a/grub-core/osdep/linux/getroot.c 1381+++ b/grub-core/osdep/linux/getroot.c 1382@@ -168,7 +168,7 @@ grub_util_raid_getmembers (const char *name, int bootable) 1383 if (ret != 0) 1384 grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno)); 1385 1386- devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); 1387+ devicelist = xcalloc (info.nr_disks + 1, sizeof (char *)); 1388 1389 for (i = 0, j = 0; j < info.nr_disks; i++) 1390 { 1391@@ -241,7 +241,7 @@ grub_find_root_devices_from_btrfs (const char *dir) 1392 return NULL; 1393 } 1394 1395- ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0])); 1396+ ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0])); 1397 1398 for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++) 1399 { 1400@@ -396,7 +396,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) 1401 if (relroot) 1402 *relroot = NULL; 1403 1404- entries = xmalloc (entry_max * sizeof (*entries)); 1405+ entries = xcalloc (entry_max, sizeof (*entries)); 1406 1407 again: 1408 fp = grub_util_fopen ("/proc/self/mountinfo", "r"); 1409diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c 1410index 65effa9f3..7d6325138 100644 1411--- a/grub-core/osdep/unix/config.c 1412+++ b/grub-core/osdep/unix/config.c 1413@@ -89,7 +89,7 @@ grub_util_load_config (struct grub_util_config *cfg) 1414 argv[0] = "sh"; 1415 argv[1] = "-c"; 1416 1417- script = xmalloc (4 * strlen (cfgfile) + 300); 1418+ script = xcalloc (4, strlen (cfgfile) + 300); 1419 1420 ptr = script; 1421 memcpy (ptr, ". '", 3); 1422diff --git a/grub-core/osdep/windows/getroot.c b/grub-core/osdep/windows/getroot.c 1423index 661d95461..eada663b2 100644 1424--- a/grub-core/osdep/windows/getroot.c 1425+++ b/grub-core/osdep/windows/getroot.c 1426@@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path) 1427 1428 for (ptr = path; *ptr; ptr++); 1429 allocsize = (ptr - path + 10) * 2; 1430- out = xmalloc (allocsize * sizeof (out[0])); 1431+ out = xcalloc (allocsize, sizeof (out[0])); 1432 1433 /* When pointing to EFI system partition GetVolumePathName fails 1434 for ESP root and returns abberant information for everything 1435diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c 1436index 355100789..0be327394 100644 1437--- a/grub-core/osdep/windows/hostdisk.c 1438+++ b/grub-core/osdep/windows/hostdisk.c 1439@@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const char *path) 1440 1441 while (1) 1442 { 1443- fpa = xmalloc (alloc * sizeof (fpa[0])); 1444+ fpa = xcalloc (alloc, sizeof (fpa[0])); 1445 1446 len = GetFullPathName (tpath, alloc, fpa, NULL); 1447 if (len >= alloc) 1448@@ -399,7 +399,7 @@ grub_util_fd_opendir (const char *name) 1449 for (l = 0; name_windows[l]; l++); 1450 for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--); 1451 l++; 1452- pattern = xmalloc ((l + 3) * sizeof (pattern[0])); 1453+ pattern = xcalloc (l + 3, sizeof (pattern[0])); 1454 memcpy (pattern, name_windows, l * sizeof (pattern[0])); 1455 pattern[l] = '\\'; 1456 pattern[l + 1] = '*'; 1457diff --git a/grub-core/osdep/windows/init.c b/grub-core/osdep/windows/init.c 1458index e8ffd62c6..6297de632 100644 1459--- a/grub-core/osdep/windows/init.c 1460+++ b/grub-core/osdep/windows/init.c 1461@@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)), 1462 LPWSTR *targv; 1463 1464 targv = CommandLineToArgvW (tcmdline, argc); 1465- *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); 1466+ *argv = xcalloc (*argc + 1, sizeof (argv[0])); 1467 1468 for (i = 0; i < *argc; i++) 1469 (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); 1470diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c 1471index 7eb53fe01..1ef86bf58 100644 1472--- a/grub-core/osdep/windows/platform.c 1473+++ b/grub-core/osdep/windows/platform.c 1474@@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, 1475 grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode")); 1476 1477 distrib8_len = grub_strlen (efi_distributor); 1478- distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8 1479- * sizeof (grub_uint16_t)); 1480+ distributor16 = xcalloc (distrib8_len + 1, 1481+ GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t)); 1482 distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8, 1483 (const grub_uint8_t *) efi_distributor, 1484 distrib8_len, 0); 1485diff --git a/grub-core/osdep/windows/relpath.c b/grub-core/osdep/windows/relpath.c 1486index cb0861744..478e8ef14 100644 1487--- a/grub-core/osdep/windows/relpath.c 1488+++ b/grub-core/osdep/windows/relpath.c 1489@@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_root (const char *path) 1490 if (dirwindows[0] && dirwindows[1] == ':') 1491 offset = 2; 1492 } 1493- ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2)); 1494+ ret = xcalloc (flen - offset + 2, sizeof (ret[0])); 1495 if (dirwindows[offset] != '\\' 1496 && dirwindows[offset] != '/' 1497 && dirwindows[offset]) 1498diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c 1499index 103f6796f..72a2e37cd 100644 1500--- a/grub-core/partmap/gpt.c 1501+++ b/grub-core/partmap/gpt.c 1502@@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, 1503 *nsectors = ctx.len; 1504 if (*nsectors > max_nsectors) 1505 *nsectors = max_nsectors; 1506- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); 1507+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); 1508 if (!*sectors) 1509 return grub_errno; 1510 for (i = 0; i < *nsectors; i++) 1511diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c 1512index 7b8e45076..ee3f24982 100644 1513--- a/grub-core/partmap/msdos.c 1514+++ b/grub-core/partmap/msdos.c 1515@@ -337,7 +337,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, 1516 avail_nsectors = *nsectors; 1517 if (*nsectors > max_nsectors) 1518 *nsectors = max_nsectors; 1519- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); 1520+ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); 1521 if (!*sectors) 1522 return grub_errno; 1523 for (i = 0; i < *nsectors; i++) 1524diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c 1525index ee299fd0e..c8d6806fe 100644 1526--- a/grub-core/script/execute.c 1527+++ b/grub-core/script/execute.c 1528@@ -553,7 +553,7 @@ gettext_append (struct grub_script_argv *result, const char *orig_str) 1529 for (iptr = orig_str; *iptr; iptr++) 1530 if (*iptr == '$') 1531 dollar_cnt++; 1532- ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt); 1533+ ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0])); 1534 1535 if (parse_string (orig_str, gettext_save_allow, &ctx, 0)) 1536 goto fail; 1537diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c 1538index 2d6085298..b5eb516be 100644 1539--- a/grub-core/tests/fake_input.c 1540+++ b/grub-core/tests/fake_input.c 1541@@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int *seq_in, int nseq_in) 1542 saved = grub_term_inputs; 1543 if (seq) 1544 grub_free (seq); 1545- seq = grub_malloc (nseq_in * sizeof (seq[0])); 1546+ seq = grub_calloc (nseq_in, sizeof (seq[0])); 1547 if (!seq) 1548 return; 1549 1550diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c 1551index 74d5b65e5..44d081069 100644 1552--- a/grub-core/tests/video_checksum.c 1553+++ b/grub-core/tests/video_checksum.c 1554@@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char *fname, 1555 { 1556 case 4: 1557 { 1558- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); 1559+ grub_uint8_t *buffer = xcalloc (3, mode_info->width); 1560 grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); 1561 grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); 1562 grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); 1563@@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char *fname, 1564 } 1565 case 3: 1566 { 1567- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); 1568+ grub_uint8_t *buffer = xcalloc (3, mode_info->width); 1569 grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); 1570 grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); 1571 grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); 1572@@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char *fname, 1573 } 1574 case 2: 1575 { 1576- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); 1577+ grub_uint8_t *buffer = xcalloc (3, mode_info->width); 1578 grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1); 1579 grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1); 1580 grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1); 1581diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c 1582index 4f83c7441..4d3195e01 100644 1583--- a/grub-core/video/capture.c 1584+++ b/grub-core/video/capture.c 1585@@ -89,7 +89,7 @@ grub_video_capture_start (const struct grub_video_mode_info *mode_info, 1586 framebuffer.mode_info = *mode_info; 1587 framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); 1588 1589- framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch); 1590+ framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch); 1591 if (!framebuffer.ptr) 1592 return grub_errno; 1593 1594diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c 1595index a2f639f66..0ebab6f57 100644 1596--- a/grub-core/video/emu/sdl.c 1597+++ b/grub-core/video/emu/sdl.c 1598@@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count, 1599 if (start + count > mode_info.number_of_colors) 1600 count = mode_info.number_of_colors - start; 1601 1602- tmp = grub_malloc (count * sizeof (tmp[0])); 1603+ tmp = grub_calloc (count, sizeof (tmp[0])); 1604 for (i = 0; i < count; i++) 1605 { 1606 tmp[i].r = palette_data[i].r; 1607diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c 1608index 01f47112d..b2f776c99 100644 1609--- a/grub-core/video/i386/pc/vga.c 1610+++ b/grub-core/video/i386/pc/vga.c 1611@@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width, unsigned int height, 1612 1613 vga_height = height ? : 480; 1614 1615- framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH); 1616+ framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH); 1617 framebuffer.front_page = 0; 1618 framebuffer.back_page = 0; 1619 if (!framebuffer.temporary_buffer) 1620diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c 1621index 777e71334..61bd64537 100644 1622--- a/grub-core/video/readers/png.c 1623+++ b/grub-core/video/readers/png.c 1624@@ -309,7 +309,7 @@ grub_png_decode_image_header (struct grub_png_data *data) 1625 if (data->is_16bit || data->is_gray || data->is_palette) 1626 #endif 1627 { 1628- data->image_data = grub_malloc (data->image_height * data->row_bytes); 1629+ data->image_data = grub_calloc (data->image_height, data->row_bytes); 1630 if (grub_errno) 1631 return grub_errno; 1632 1633diff --git a/include/grub/unicode.h b/include/grub/unicode.h 1634index a0403e91f..4de986a85 100644 1635--- a/include/grub/unicode.h 1636+++ b/include/grub/unicode.h 1637@@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in) 1638 grub_memcpy (out, in, sizeof (*in)); 1639 if (in->ncomb > ARRAY_SIZE (out->combining_inline)) 1640 { 1641- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); 1642+ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); 1643 if (!out->combining_ptr) 1644 { 1645 grub_free (out); 1646@@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unicode_glyph *out, 1647 grub_memcpy (out, in, sizeof (*in)); 1648 if (in->ncomb > ARRAY_SIZE (out->combining_inline)) 1649 { 1650- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); 1651+ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); 1652 if (!out->combining_ptr) 1653 return; 1654 grub_memcpy (out->combining_ptr, in->combining_ptr, 1655diff --git a/util/getroot.c b/util/getroot.c 1656index 847406fba..a5eaa64fd 100644 1657--- a/util/getroot.c 1658+++ b/util/getroot.c 1659@@ -200,7 +200,7 @@ make_device_name (const char *drive) 1660 char *ret, *ptr; 1661 const char *iptr; 1662 1663- ret = xmalloc (strlen (drive) * 2); 1664+ ret = xcalloc (2, strlen (drive)); 1665 ptr = ret; 1666 for (iptr = drive; *iptr; iptr++) 1667 { 1668diff --git a/util/grub-file.c b/util/grub-file.c 1669index 50c18b683..b2e7dd69f 100644 1670--- a/util/grub-file.c 1671+++ b/util/grub-file.c 1672@@ -54,7 +54,7 @@ main (int argc, char *argv[]) 1673 1674 grub_util_host_init (&argc, &argv); 1675 1676- argv2 = xmalloc (argc * sizeof (argv2[0])); 1677+ argv2 = xcalloc (argc, sizeof (argv2[0])); 1678 1679 if (argc == 2 && strcmp (argv[1], "--version") == 0) 1680 { 1681diff --git a/util/grub-fstest.c b/util/grub-fstest.c 1682index f14e02d97..57246af7c 100644 1683--- a/util/grub-fstest.c 1684+++ b/util/grub-fstest.c 1685@@ -650,7 +650,7 @@ argp_parser (int key, char *arg, struct argp_state *state) 1686 if (args_count < num_disks) 1687 { 1688 if (args_count == 0) 1689- images = xmalloc (num_disks * sizeof (images[0])); 1690+ images = xcalloc (num_disks, sizeof (images[0])); 1691 images[args_count] = grub_canonicalize_file_name (arg); 1692 args_count++; 1693 return 0; 1694@@ -734,7 +734,7 @@ main (int argc, char *argv[]) 1695 1696 grub_util_host_init (&argc, &argv); 1697 1698- args = xmalloc (argc * sizeof (args[0])); 1699+ args = xcalloc (argc, sizeof (args[0])); 1700 1701 argp_parse (&argp, argc, argv, 0, 0, 0); 1702 1703diff --git a/util/grub-install-common.c b/util/grub-install-common.c 1704index ca0ac612a..0295d40f5 100644 1705--- a/util/grub-install-common.c 1706+++ b/util/grub-install-common.c 1707@@ -286,7 +286,7 @@ handle_install_list (struct install_list *il, const char *val, 1708 il->n_entries++; 1709 } 1710 il->n_alloc = il->n_entries + 1; 1711- il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0])); 1712+ il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0])); 1713 ptr = val; 1714 for (ce = il->entries; ; ce++) 1715 { 1716diff --git a/util/grub-install.c b/util/grub-install.c 1717index 8a55ad4b8..a82725f29 100644 1718--- a/util/grub-install.c 1719+++ b/util/grub-install.c 1720@@ -626,7 +626,7 @@ device_map_check_duplicates (const char *dev_map) 1721 if (! fp) 1722 return; 1723 1724- d = xmalloc (alloced * sizeof (d[0])); 1725+ d = xcalloc (alloced, sizeof (d[0])); 1726 1727 while (fgets (buf, sizeof (buf), fp)) 1728 { 1729@@ -1260,7 +1260,7 @@ main (int argc, char *argv[]) 1730 ndev++; 1731 } 1732 1733- grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); 1734+ grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0])); 1735 1736 for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, 1737 curdrive++) 1738diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c 1739index bc087c2b5..d97d0e7be 100644 1740--- a/util/grub-mkimagexx.c 1741+++ b/util/grub-mkimagexx.c 1742@@ -2294,10 +2294,8 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, 1743 + grub_host_to_target16 (e->e_shstrndx) * smd.section_entsize); 1744 smd.strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); 1745 1746- smd.addrs = xmalloc (sizeof (*smd.addrs) * smd.num_sections); 1747- memset (smd.addrs, 0, sizeof (*smd.addrs) * smd.num_sections); 1748- smd.vaddrs = xmalloc (sizeof (*smd.vaddrs) * smd.num_sections); 1749- memset (smd.vaddrs, 0, sizeof (*smd.vaddrs) * smd.num_sections); 1750+ smd.addrs = xcalloc (smd.num_sections, sizeof (*smd.addrs)); 1751+ smd.vaddrs = xcalloc (smd.num_sections, sizeof (*smd.vaddrs)); 1752 1753 SUFFIX (locate_sections) (e, kernel_path, &smd, layout, image_target); 1754 1755diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c 1756index ce2cbc4f1..51831027f 100644 1757--- a/util/grub-mkrescue.c 1758+++ b/util/grub-mkrescue.c 1759@@ -441,8 +441,8 @@ main (int argc, char *argv[]) 1760 xorriso = xstrdup ("xorriso"); 1761 label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2"); 1762 1763- argp_argv = xmalloc (sizeof (argp_argv[0]) * argc); 1764- xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc); 1765+ argp_argv = xcalloc (argc, sizeof (argp_argv[0])); 1766+ xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0])); 1767 1768 xorriso_tail_argc = 0; 1769 /* Program name */ 1770diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c 1771index 4907d44c0..edf309717 100644 1772--- a/util/grub-mkstandalone.c 1773+++ b/util/grub-mkstandalone.c 1774@@ -296,7 +296,7 @@ main (int argc, char *argv[]) 1775 grub_util_host_init (&argc, &argv); 1776 grub_util_disable_fd_syncs (); 1777 1778- files = xmalloc ((argc + 1) * sizeof (files[0])); 1779+ files = xcalloc (argc + 1, sizeof (files[0])); 1780 1781 argp_parse (&argp, argc, argv, 0, 0, 0); 1782 1783diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c 1784index 0d4084a10..11331294f 100644 1785--- a/util/grub-pe2elf.c 1786+++ b/util/grub-pe2elf.c 1787@@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char *name, char *image, 1788 char *pe_strtab = (image + pe_chdr->symtab_offset 1789 + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); 1790 1791- section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int)); 1792+ section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int)); 1793 section_map[0] = 0; 1794- shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0])); 1795+ shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0])); 1796 idx = 1; 1797 idx_reloc = pe_chdr->num_sections + 1; 1798 1799@@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const char *name, char *image, 1800 1801 pe_sec = pe_shdr + shdr[i].sh_link; 1802 pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset); 1803- rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t)); 1804+ rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t)); 1805 num_rels = 0; 1806 modified = 0; 1807 1808@@ -365,12 +365,10 @@ write_symbol_table (FILE* fp, const char *name, char *image, 1809 pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset); 1810 pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols); 1811 1812- symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) * 1813- sizeof (Elf_Sym)); 1814- memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym)); 1815+ symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym)); 1816 num_syms = 1; 1817 1818- symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int)); 1819+ symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int)); 1820 1821 for (i = 0; i < (int) pe_chdr->num_symbols; 1822 i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1) 1823diff --git a/util/grub-probe.c b/util/grub-probe.c 1824index 81d27eead..cbe6ed94c 100644 1825--- a/util/grub-probe.c 1826+++ b/util/grub-probe.c 1827@@ -361,8 +361,8 @@ probe (const char *path, char **device_names, char delim) 1828 grub_util_pull_device (*curdev); 1829 ndev++; 1830 } 1831- 1832- drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); 1833+ 1834+ drives_names = xcalloc (ndev + 1, sizeof (drives_names[0])); 1835 1836 for (curdev = device_names, curdrive = drives_names; *curdev; curdev++, 1837 curdrive++) 1838-- 18392.26.2 1840 1841