Blame SOURCES/0284-calloc-Use-calloc-at-most-places.patch

c294fc
From 778ddaeac8a8a821f6844ec8b8c404d0e437991f Mon Sep 17 00:00:00 2001
c294fc
From: Peter Jones <pjones@redhat.com>
c294fc
Date: Mon, 15 Jun 2020 12:26:01 -0400
c294fc
Subject: [PATCH 284/314] calloc: Use calloc() at most places
c294fc
c294fc
This modifies most of the places we do some form of:
c294fc
c294fc
  X = malloc(Y * Z);
c294fc
c294fc
to use calloc(Y, Z) instead.
c294fc
c294fc
Among other issues, this fixes:
c294fc
  - allocation of integer overflow in grub_png_decode_image_header()
c294fc
    reported by Chris Coulson,
c294fc
  - allocation of integer overflow in luks_recover_key()
c294fc
    reported by Chris Coulson,
c294fc
  - allocation of integer overflow in grub_lvm_detect()
c294fc
    reported by Chris Coulson.
c294fc
c294fc
Fixes: CVE-2020-14308
c294fc
c294fc
Signed-off-by: Peter Jones <pjones@redhat.com>
c294fc
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
c294fc
Upstream-commit-id: 48eeedf1e4b
c294fc
---
c294fc
 grub-core/bus/usb/usbhub.c                |  8 ++--
c294fc
 grub-core/commands/efi/lsefisystab.c      |  3 +-
c294fc
 grub-core/commands/legacycfg.c            |  6 +--
c294fc
 grub-core/commands/menuentry.c            |  2 +-
c294fc
 grub-core/commands/nativedisk.c           |  2 +-
c294fc
 grub-core/commands/parttool.c             | 12 ++++--
c294fc
 grub-core/commands/regexp.c               |  2 +-
c294fc
 grub-core/commands/search_wrap.c          |  2 +-
c294fc
 grub-core/disk/diskfilter.c               |  4 +-
c294fc
 grub-core/disk/ieee1275/ofdisk.c          |  2 +-
c294fc
 grub-core/disk/ldm.c                      | 14 +++----
c294fc
 grub-core/disk/luks.c                     |  2 +-
c294fc
 grub-core/disk/lvm.c                      |  8 ++--
c294fc
 grub-core/disk/xen/xendisk.c              |  2 +-
c294fc
 grub-core/efiemu/loadcore.c               |  2 +-
c294fc
 grub-core/efiemu/mm.c                     |  6 +--
c294fc
 grub-core/font/font.c                     |  3 +-
c294fc
 grub-core/fs/affs.c                       |  6 +--
c294fc
 grub-core/fs/btrfs.c                      |  4 +-
c294fc
 grub-core/fs/hfs.c                        |  2 +-
c294fc
 grub-core/fs/hfsplus.c                    | 45 +++++++++++++++--------
c294fc
 grub-core/fs/iso9660.c                    |  2 +-
c294fc
 grub-core/fs/ntfs.c                       |  4 +-
c294fc
 grub-core/fs/sfs.c                        |  2 +-
c294fc
 grub-core/fs/tar.c                        |  2 +-
c294fc
 grub-core/fs/udf.c                        |  4 +-
c294fc
 grub-core/fs/zfs/zfs.c                    |  4 +-
c294fc
 grub-core/gfxmenu/gui_string_util.c       |  2 +-
c294fc
 grub-core/gfxmenu/widget-box.c            |  4 +-
c294fc
 grub-core/io/gzio.c                       |  2 +-
c294fc
 grub-core/kern/efi/efi.c                  | 33 ++++++++++++++---
c294fc
 grub-core/kern/emu/hostdisk.c             |  2 +-
c294fc
 grub-core/kern/fs.c                       |  2 +-
c294fc
 grub-core/kern/misc.c                     |  2 +-
c294fc
 grub-core/kern/parser.c                   |  2 +-
c294fc
 grub-core/kern/uboot/uboot.c              |  2 +-
c294fc
 grub-core/lib/libgcrypt/cipher/ac.c       |  8 ++--
c294fc
 grub-core/lib/libgcrypt/cipher/primegen.c |  4 +-
c294fc
 grub-core/lib/libgcrypt/cipher/pubkey.c   |  4 +-
c294fc
 grub-core/lib/priority_queue.c            |  2 +-
c294fc
 grub-core/lib/reed_solomon.c              |  7 ++--
c294fc
 grub-core/lib/relocator.c                 | 10 ++---
c294fc
 grub-core/loader/arm/linux.c              |  2 +-
c294fc
 grub-core/loader/efi/chainloader.c        | 11 ++++--
c294fc
 grub-core/loader/i386/bsdXX.c             |  2 +-
c294fc
 grub-core/loader/i386/xnu.c               |  4 +-
c294fc
 grub-core/loader/macho.c                  |  2 +-
c294fc
 grub-core/loader/multiboot_elfxx.c        |  2 +-
c294fc
 grub-core/loader/xnu.c                    |  2 +-
c294fc
 grub-core/mmap/mmap.c                     |  4 +-
c294fc
 grub-core/net/bootp.c                     |  2 +-
c294fc
 grub-core/net/dns.c                       | 10 ++---
c294fc
 grub-core/net/net.c                       |  4 +-
c294fc
 grub-core/normal/charset.c                | 10 ++---
c294fc
 grub-core/normal/cmdline.c                | 14 +++----
c294fc
 grub-core/normal/menu_entry.c             | 14 +++----
c294fc
 grub-core/normal/menu_text.c              |  4 +-
c294fc
 grub-core/normal/term.c                   |  4 +-
c294fc
 grub-core/osdep/linux/getroot.c           |  6 +--
c294fc
 grub-core/osdep/unix/config.c             |  2 +-
c294fc
 grub-core/osdep/windows/getroot.c         |  2 +-
c294fc
 grub-core/osdep/windows/hostdisk.c        |  4 +-
c294fc
 grub-core/osdep/windows/init.c            |  2 +-
c294fc
 grub-core/osdep/windows/platform.c        |  4 +-
c294fc
 grub-core/osdep/windows/relpath.c         |  2 +-
c294fc
 grub-core/partmap/gpt.c                   |  2 +-
c294fc
 grub-core/partmap/msdos.c                 |  2 +-
c294fc
 grub-core/script/execute.c                |  2 +-
c294fc
 grub-core/tests/fake_input.c              |  2 +-
c294fc
 grub-core/tests/video_checksum.c          |  6 +--
c294fc
 grub-core/video/capture.c                 |  2 +-
c294fc
 grub-core/video/emu/sdl.c                 |  2 +-
c294fc
 grub-core/video/i386/pc/vga.c             |  2 +-
c294fc
 grub-core/video/readers/png.c             |  2 +-
c294fc
 util/getroot.c                            |  2 +-
c294fc
 util/grub-file.c                          |  2 +-
c294fc
 util/grub-fstest.c                        |  4 +-
c294fc
 util/grub-install-common.c                |  2 +-
c294fc
 util/grub-install.c                       |  4 +-
c294fc
 util/grub-mkimagexx.c                     |  6 +--
c294fc
 util/grub-mkrescue.c                      |  4 +-
c294fc
 util/grub-mkstandalone.c                  |  2 +-
c294fc
 util/grub-pe2elf.c                        | 12 +++---
c294fc
 util/grub-probe.c                         |  4 +-
c294fc
 include/grub/unicode.h                    |  4 +-
c294fc
 85 files changed, 231 insertions(+), 191 deletions(-)
c294fc
c294fc
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
c294fc
index 34a7ff1b5f8..a06cce302d2 100644
c294fc
--- a/grub-core/bus/usb/usbhub.c
c294fc
+++ b/grub-core/bus/usb/usbhub.c
c294fc
@@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev)
c294fc
   grub_usb_set_configuration (dev, 1);
c294fc
 
c294fc
   dev->nports = hubdesc.portcnt;
c294fc
-  dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0]));
c294fc
-  dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0]));
c294fc
+  dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0]));
c294fc
+  dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0]));
c294fc
   if (!dev->children || !dev->ports)
c294fc
     {
c294fc
       grub_free (dev->children);
c294fc
@@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (grub_usb_controller_t controller, void *d
c294fc
 
c294fc
   /* Query the number of ports the root Hub has.  */
c294fc
   hub->nports = controller->dev->hubports (controller);
c294fc
-  hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports);
c294fc
-  hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports);
c294fc
+  hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0]));
c294fc
+  hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0]));
c294fc
   if (!hub->devices || !hub->ports)
c294fc
     {
c294fc
       grub_free (hub->devices);
c294fc
diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c
c294fc
index df103022188..cd81507f5d4 100644
c294fc
--- a/grub-core/commands/efi/lsefisystab.c
c294fc
+++ b/grub-core/commands/efi/lsefisystab.c
c294fc
@@ -71,7 +71,8 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
c294fc
     grub_printf ("Vendor: ");
c294fc
     
c294fc
     for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++);
c294fc
-    vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1);
c294fc
+    /* Allocate extra 3 bytes to simplify math. */
c294fc
+    vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1);
c294fc
     if (!vendor)
c294fc
       return grub_errno;
c294fc
     *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor,
c294fc
diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c
c294fc
index f9d7627bdc3..da66a8927c4 100644
c294fc
--- a/grub-core/commands/legacycfg.c
c294fc
+++ b/grub-core/commands/legacycfg.c
c294fc
@@ -314,7 +314,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
c294fc
   if (argc < 2)
c294fc
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
c294fc
 
c294fc
-  cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1));
c294fc
+  cutargs = grub_calloc (argc - 1, sizeof (cutargs[0]));
c294fc
   if (!cutargs)
c294fc
     return grub_errno;
c294fc
   cutargc = argc - 1;
c294fc
@@ -436,7 +436,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
c294fc
 	    {
c294fc
 	      char rbuf[3] = "-r";
c294fc
 	      bsdargc = cutargc + 2;
c294fc
-	      bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc);
c294fc
+	      bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0]));
c294fc
 	      if (!bsdargs)
c294fc
 		{
c294fc
 		  err = grub_errno;
c294fc
@@ -559,7 +559,7 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused
c294fc
 	return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"),
c294fc
 			   "module");
c294fc
 
c294fc
-      newargs = grub_malloc ((argc + 1) * sizeof (newargs[0]));
c294fc
+      newargs = grub_calloc (argc + 1, sizeof (newargs[0]));
c294fc
       if (!newargs)
c294fc
 	return grub_errno;
c294fc
       grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0]));
c294fc
diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c
c294fc
index 7004e08ce78..4b5fcf2ce9a 100644
c294fc
--- a/grub-core/commands/menuentry.c
c294fc
+++ b/grub-core/commands/menuentry.c
c294fc
@@ -157,7 +157,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
c294fc
   grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id);
c294fc
 
c294fc
   /* Save argc, args to pass as parameters to block arg later. */
c294fc
-  menu_args = grub_malloc (sizeof (char*) * (argc + 1));
c294fc
+  menu_args = grub_calloc (argc + 1, sizeof (char *));
c294fc
   if (! menu_args)
c294fc
     goto fail;
c294fc
 
c294fc
diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c
c294fc
index 2f56a870e68..d69214f6de0 100644
c294fc
--- a/grub-core/commands/nativedisk.c
c294fc
+++ b/grub-core/commands/nativedisk.c
c294fc
@@ -194,7 +194,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
c294fc
   else
c294fc
     path_prefix = prefix;
c294fc
 
c294fc
-  mods = grub_malloc (argc * sizeof (mods[0]));
c294fc
+  mods = grub_calloc (argc, sizeof (mods[0]));
c294fc
   if (!mods)
c294fc
     return grub_errno;
c294fc
 
c294fc
diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c
c294fc
index 693e2cb42fc..36dadc0b1db 100644
c294fc
--- a/grub-core/commands/parttool.c
c294fc
+++ b/grub-core/commands/parttool.c
c294fc
@@ -59,7 +59,13 @@ grub_parttool_register(const char *part_name,
c294fc
   for (nargs = 0; args[nargs].name != 0; nargs++);
c294fc
   cur->nargs = nargs;
c294fc
   cur->args = (struct grub_parttool_argdesc *)
c294fc
-    grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc));
c294fc
+    grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc));
c294fc
+  if (!cur->args)
c294fc
+    {
c294fc
+      grub_free (cur);
c294fc
+      curhandle--;
c294fc
+      return -1;
c294fc
+    }
c294fc
   grub_memcpy (cur->args, args,
c294fc
 	       (nargs + 1) * sizeof (struct grub_parttool_argdesc));
c294fc
 
c294fc
@@ -257,7 +263,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
c294fc
 	return err;
c294fc
       }
c294fc
 
c294fc
-  parsed = (int *) grub_zalloc (argc * sizeof (int));
c294fc
+  parsed = (int *) grub_calloc (argc, sizeof (int));
c294fc
 
c294fc
   for (i = 1; i < argc; i++)
c294fc
     if (! parsed[i])
c294fc
@@ -290,7 +296,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
c294fc
 	  }
c294fc
 	ptool = cur;
c294fc
 	pargs = (struct grub_parttool_args *)
c294fc
-	  grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args));
c294fc
+	  grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args));
c294fc
 	for (j = i; j < argc; j++)
c294fc
 	  if (! parsed[j])
c294fc
 	    {
c294fc
diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c
c294fc
index f00b184c81e..4019164f365 100644
c294fc
--- a/grub-core/commands/regexp.c
c294fc
+++ b/grub-core/commands/regexp.c
c294fc
@@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args)
c294fc
   if (ret)
c294fc
     goto fail;
c294fc
 
c294fc
-  matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1));
c294fc
+  matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches));
c294fc
   if (! matches)
c294fc
     goto fail;
c294fc
 
c294fc
diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c
c294fc
index d7fd26b9405..47fc8eb9966 100644
c294fc
--- a/grub-core/commands/search_wrap.c
c294fc
+++ b/grub-core/commands/search_wrap.c
c294fc
@@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
c294fc
     for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++)
c294fc
       nhints++;
c294fc
 
c294fc
-  hints = grub_malloc (sizeof (hints[0]) * nhints);
c294fc
+  hints = grub_calloc (nhints, sizeof (hints[0]));
c294fc
   if (!hints)
c294fc
     return grub_errno;
c294fc
   j = 0;
c294fc
diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c
c294fc
index 6f901c0adf7..2be019269b1 100644
c294fc
--- a/grub-core/disk/diskfilter.c
c294fc
+++ b/grub-core/disk/diskfilter.c
c294fc
@@ -1134,7 +1134,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb,
c294fc
   array->lvs->segments->node_count = nmemb;
c294fc
   array->lvs->segments->raid_member_size = disk_size;
c294fc
   array->lvs->segments->nodes
c294fc
-    = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0]));
c294fc
+    = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0]));
c294fc
   array->lvs->segments->stripe_size = stripe_size;
c294fc
   for (i = 0; i < nmemb; i++)
c294fc
     {
c294fc
@@ -1226,7 +1226,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id,
c294fc
 	  grub_partition_t p;
c294fc
 	  for (p = disk->partition; p; p = p->parent)
c294fc
 	    s++;
c294fc
-	  pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0]));
c294fc
+	  pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0]));
c294fc
 	  s = 0;
c294fc
 	  for (p = disk->partition; p; p = p->parent)
c294fc
 	    pv->partmaps[s++] = xstrdup (p->partmap->name);
c294fc
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
c294fc
index 235c0fe2c76..d887d4b6eee 100644
c294fc
--- a/grub-core/disk/ieee1275/ofdisk.c
c294fc
+++ b/grub-core/disk/ieee1275/ofdisk.c
c294fc
@@ -297,7 +297,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
c294fc
       /* Power machines documentation specify 672 as maximum SAS disks in
c294fc
          one system. Using a slightly larger value to be safe. */
c294fc
       table_size = 768;
c294fc
-      table = grub_malloc (table_size * sizeof (grub_uint64_t));
c294fc
+      table = grub_calloc (table_size, sizeof (grub_uint64_t));
c294fc
 
c294fc
       if (!table)
c294fc
         {
c294fc
diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c
c294fc
index 2a22d2d6c1c..e6323701ab3 100644
c294fc
--- a/grub-core/disk/ldm.c
c294fc
+++ b/grub-core/disk/ldm.c
c294fc
@@ -323,8 +323,8 @@ make_vg (grub_disk_t disk,
c294fc
 	  lv->segments->type = GRUB_DISKFILTER_MIRROR;
c294fc
 	  lv->segments->node_count = 0;
c294fc
 	  lv->segments->node_alloc = 8;
c294fc
-	  lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes)
c294fc
-					     * lv->segments->node_alloc);
c294fc
+	  lv->segments->nodes = grub_calloc (lv->segments->node_alloc,
c294fc
+					     sizeof (*lv->segments->nodes));
c294fc
 	  if (!lv->segments->nodes)
c294fc
 	    goto fail2;
c294fc
 	  ptr = vblk[i].dynamic;
c294fc
@@ -543,8 +543,8 @@ make_vg (grub_disk_t disk,
c294fc
 	    {
c294fc
 	      comp->segment_alloc = 8;
c294fc
 	      comp->segment_count = 0;
c294fc
-	      comp->segments = grub_malloc (sizeof (*comp->segments)
c294fc
-					    * comp->segment_alloc);
c294fc
+	      comp->segments = grub_calloc (comp->segment_alloc,
c294fc
+					    sizeof (*comp->segments));
c294fc
 	      if (!comp->segments)
c294fc
 		goto fail2;
c294fc
 	    }
c294fc
@@ -590,8 +590,8 @@ make_vg (grub_disk_t disk,
c294fc
 		}
c294fc
 	      comp->segments->node_count = read_int (ptr + 1, *ptr);
c294fc
 	      comp->segments->node_alloc = comp->segments->node_count;
c294fc
-	      comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes)
c294fc
-						   * comp->segments->node_alloc);
c294fc
+	      comp->segments->nodes = grub_calloc (comp->segments->node_alloc,
c294fc
+						   sizeof (*comp->segments->nodes));
c294fc
 	      if (!lv->segments->nodes)
c294fc
 		goto fail2;
c294fc
 	    }
c294fc
@@ -1017,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors,
c294fc
       *nsectors = lv->size;
c294fc
       if (*nsectors > max_nsectors)
c294fc
 	*nsectors = max_nsectors;
c294fc
-      *sectors = grub_malloc (*nsectors * sizeof (**sectors));
c294fc
+      *sectors = grub_calloc (*nsectors, sizeof (**sectors));
c294fc
       if (!*sectors)
c294fc
 	return grub_errno;
c294fc
       for (i = 0; i < *nsectors; i++)
c294fc
diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c
c294fc
index 86c50c61217..18b3a8bb1d3 100644
c294fc
--- a/grub-core/disk/luks.c
c294fc
+++ b/grub-core/disk/luks.c
c294fc
@@ -336,7 +336,7 @@ luks_recover_key (grub_disk_t source,
c294fc
 	&& grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes)
c294fc
       max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes);
c294fc
 
c294fc
-  split_key = grub_malloc (keysize * max_stripes);
c294fc
+  split_key = grub_calloc (keysize, max_stripes);
c294fc
   if (!split_key)
c294fc
     return grub_errno;
c294fc
 
c294fc
diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c
c294fc
index 7b265c780c3..d1df640b311 100644
c294fc
--- a/grub-core/disk/lvm.c
c294fc
+++ b/grub-core/disk/lvm.c
c294fc
@@ -173,7 +173,7 @@ grub_lvm_detect (grub_disk_t disk,
c294fc
      first one.  */
c294fc
 
c294fc
   /* Allocate buffer space for the circular worst-case scenario. */
c294fc
-  metadatabuf = grub_malloc (2 * mda_size);
c294fc
+  metadatabuf = grub_calloc (2, mda_size);
c294fc
   if (! metadatabuf)
c294fc
     goto fail;
c294fc
 
c294fc
@@ -426,7 +426,7 @@ grub_lvm_detect (grub_disk_t disk,
c294fc
 #endif
c294fc
 		  goto lvs_fail;
c294fc
 		}
c294fc
-	      lv->segments = grub_zalloc (sizeof (*seg) * lv->segment_count);
c294fc
+	      lv->segments = grub_calloc (lv->segment_count, sizeof (*seg));
c294fc
 	      seg = lv->segments;
c294fc
 
c294fc
 	      for (i = 0; i < lv->segment_count; i++)
c294fc
@@ -483,8 +483,8 @@ grub_lvm_detect (grub_disk_t disk,
c294fc
 		      if (seg->node_count != 1)
c294fc
 			seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = ");
c294fc
 
c294fc
-		      seg->nodes = grub_zalloc (sizeof (*stripe)
c294fc
-						* seg->node_count);
c294fc
+		      seg->nodes = grub_calloc (seg->node_count,
c294fc
+						sizeof (*stripe));
c294fc
 		      stripe = seg->nodes;
c294fc
 
c294fc
 		      p = grub_strstr (p, "stripes = [");
c294fc
diff --git a/grub-core/disk/xen/xendisk.c b/grub-core/disk/xen/xendisk.c
c294fc
index b18a9238d87..c1b331edba7 100644
c294fc
--- a/grub-core/disk/xen/xendisk.c
c294fc
+++ b/grub-core/disk/xen/xendisk.c
c294fc
@@ -426,7 +426,7 @@ grub_xendisk_init (void)
c294fc
   if (!ctr)
c294fc
     return;
c294fc
 
c294fc
-  virtdisks = grub_malloc (ctr * sizeof (virtdisks[0]));
c294fc
+  virtdisks = grub_calloc (ctr, sizeof (virtdisks[0]));
c294fc
   if (!virtdisks)
c294fc
     return;
c294fc
   if (grub_xenstore_dir ("device/vbd", fill, &ctr))
c294fc
diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c
c294fc
index 44085ef818e..2b924623f51 100644
c294fc
--- a/grub-core/efiemu/loadcore.c
c294fc
+++ b/grub-core/efiemu/loadcore.c
c294fc
@@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
c294fc
 
c294fc
   grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize;
c294fc
   grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *)
c294fc
-    grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms);
c294fc
+    grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym));
c294fc
 
c294fc
   /* Relocators */
c294fc
   for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
c294fc
diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c
c294fc
index 52a032f7b2e..9b8e0d0ad1a 100644
c294fc
--- a/grub-core/efiemu/mm.c
c294fc
+++ b/grub-core/efiemu/mm.c
c294fc
@@ -554,11 +554,11 @@ grub_efiemu_mmap_sort_and_uniq (void)
c294fc
   /* Initialize variables*/
c294fc
   grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE);
c294fc
   scanline_events = (struct grub_efiemu_mmap_scan *)
c294fc
-    grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num);
c294fc
+    grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2);
c294fc
 
c294fc
   /* Number of chunks can't increase more than by factor of 2 */
c294fc
   result = (grub_efi_memory_descriptor_t *)
c294fc
-    grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num);
c294fc
+    grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2);
c294fc
   if (!result || !scanline_events)
c294fc
     {
c294fc
       grub_free (result);
c294fc
@@ -660,7 +660,7 @@ grub_efiemu_mm_do_alloc (void)
c294fc
 
c294fc
   /* Preallocate mmap */
c294fc
   efiemu_mmap = (grub_efi_memory_descriptor_t *)
c294fc
-    grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t));
c294fc
+    grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t));
c294fc
   if (!efiemu_mmap)
c294fc
     {
c294fc
       grub_efiemu_unload ();
c294fc
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
c294fc
index 53d76a64d04..68967dc1c2b 100644
c294fc
--- a/grub-core/font/font.c
c294fc
+++ b/grub-core/font/font.c
c294fc
@@ -293,8 +293,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
c294fc
   font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE;
c294fc
 
c294fc
   /* Allocate the character index array.  */
c294fc
-  font->char_index = grub_malloc (font->num_chars
c294fc
-				  * sizeof (struct char_index_entry));
c294fc
+  font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry));
c294fc
   if (!font->char_index)
c294fc
     return 1;
c294fc
   font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
c294fc
diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c
c294fc
index f673897e0fd..91073795f90 100644
c294fc
--- a/grub-core/fs/affs.c
c294fc
+++ b/grub-core/fs/affs.c
c294fc
@@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node_t node)
c294fc
       return 0;
c294fc
     }
c294fc
   latin1[symlink_size] = 0;
c294fc
-  utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1);
c294fc
+  utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size);
c294fc
   if (!utf8)
c294fc
     {
c294fc
       grub_free (latin1);
c294fc
@@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
c294fc
 	return 1;
c294fc
     }
c294fc
 
c294fc
-  hashtable = grub_zalloc (data->htsize * sizeof (*hashtable));
c294fc
+  hashtable = grub_calloc (data->htsize, sizeof (*hashtable));
c294fc
   if (!hashtable)
c294fc
     return 1;
c294fc
 
c294fc
@@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, char **label)
c294fc
       len = file.namelen;
c294fc
       if (len > sizeof (file.name))
c294fc
 	len = sizeof (file.name);
c294fc
-      *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1);
c294fc
+      *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len);
c294fc
       if (*label)
c294fc
 	*grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0';
c294fc
     }
c294fc
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
c294fc
index dac73b2fa8b..8c8aa9c3103 100644
c294fc
--- a/grub-core/fs/btrfs.c
c294fc
+++ b/grub-core/fs/btrfs.c
c294fc
@@ -404,7 +404,7 @@ lower_bound (struct grub_btrfs_data *data,
c294fc
     {
c294fc
       desc->allocated = 16;
c294fc
       desc->depth = 0;
c294fc
-      desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated);
c294fc
+      desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0]));
c294fc
       if (!desc->data)
c294fc
 	return grub_errno;
c294fc
     }
c294fc
@@ -2056,7 +2056,7 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)),
c294fc
   *nsectors = 64 * 2 - 1;
c294fc
   if (*nsectors > max_nsectors)
c294fc
     *nsectors = max_nsectors;
c294fc
-  *sectors = grub_malloc (*nsectors * sizeof (**sectors));
c294fc
+  *sectors = grub_calloc (*nsectors, sizeof (**sectors));
c294fc
   if (!*sectors)
c294fc
     return grub_errno;
c294fc
   for (i = 0; i < *nsectors; i++)
c294fc
diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c
c294fc
index fc36831789c..3fd4eec202c 100644
c294fc
--- a/grub-core/fs/hfs.c
c294fc
+++ b/grub-core/fs/hfs.c
c294fc
@@ -1360,7 +1360,7 @@ grub_hfs_label (grub_device_t device, char **label)
c294fc
       grub_size_t len = data->sblock.volname[0];
c294fc
       if (len > sizeof (data->sblock.volname) - 1)
c294fc
 	len = sizeof (data->sblock.volname) - 1;
c294fc
-      *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1);
c294fc
+      *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len);
c294fc
       if (*label)
c294fc
 	macroman_to_utf8 (*label, data->sblock.volname + 1,
c294fc
 			  len + 1, 0);
c294fc
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
c294fc
index 21159e858ab..f1cd72398ec 100644
c294fc
--- a/grub-core/fs/hfsplus.c
c294fc
+++ b/grub-core/fs/hfsplus.c
c294fc
@@ -661,6 +661,7 @@ list_nodes (void *record, void *hook_arg)
c294fc
   char *filename;
c294fc
   int i;
c294fc
   struct grub_fshelp_node *node;
c294fc
+  grub_uint16_t *keyname;
c294fc
   struct grub_hfsplus_catfile *fileinfo;
c294fc
   enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN;
c294fc
   struct list_nodes_ctx *ctx = hook_arg;
c294fc
@@ -719,32 +720,34 @@ list_nodes (void *record, void *hook_arg)
c294fc
   if (! filename)
c294fc
     return 0;
c294fc
 
c294fc
+  keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname));
c294fc
+  if (!keyname)
c294fc
+    {
c294fc
+      grub_free (filename);
c294fc
+      return 0;
c294fc
+    }
c294fc
+
c294fc
   /* Make sure the byte order of the UTF16 string is correct.  */
c294fc
   for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++)
c294fc
     {
c294fc
-      catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]);
c294fc
+      keyname[i] = grub_be_to_cpu16 (catkey->name[i]);
c294fc
 
c294fc
-      if (catkey->name[i] == '/')
c294fc
-	catkey->name[i] = ':';
c294fc
+      if (keyname[i] == '/')
c294fc
+	keyname[i] = ':';
c294fc
 
c294fc
       /* If the name is obviously invalid, skip this node.  */
c294fc
-      if (catkey->name[i] == 0)
c294fc
+      if (keyname[i] == 0)
c294fc
 	{
c294fc
 	  grub_free (filename);
c294fc
+	  grub_free (keyname);
c294fc
 	  return 0;
c294fc
 	}
c294fc
     }
c294fc
 
c294fc
-  *grub_utf16_to_utf8 ((grub_uint8_t *) filename, catkey->name,
c294fc
+  *grub_utf16_to_utf8 ((grub_uint8_t *) filename, keyname,
c294fc
 		       grub_be_to_cpu16 (catkey->namelen)) = '\0';
c294fc
 
c294fc
-  /* Restore the byte order to what it was previously.  */
c294fc
-  for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++)
c294fc
-    {
c294fc
-      if (catkey->name[i] == ':')
c294fc
-	catkey->name[i] = '/';
c294fc
-      catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]);
c294fc
-    }
c294fc
+  grub_free (keyname);
c294fc
 
c294fc
   /* hfs+ is case insensitive.  */
c294fc
   if (! ctx->dir->data->case_sensitive)
c294fc
@@ -975,6 +978,7 @@ grub_hfsplus_label (grub_device_t device, char **label)
c294fc
   grub_disk_t disk = device->disk;
c294fc
   struct grub_hfsplus_catkey *catkey;
c294fc
   int i, label_len;
c294fc
+  grub_uint16_t *label_name;
c294fc
   struct grub_hfsplus_key_internal intern;
c294fc
   struct grub_hfsplus_btnode *node = NULL;
c294fc
   grub_disk_addr_t ptr = 0;
c294fc
@@ -1003,22 +1007,31 @@ grub_hfsplus_label (grub_device_t device, char **label)
c294fc
     grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr);
c294fc
 
c294fc
   label_len = grub_be_to_cpu16 (catkey->namelen);
c294fc
+  label_name = grub_calloc (label_len, sizeof (*label_name));
c294fc
+  if (!label_name)
c294fc
+    {
c294fc
+      grub_free (node);
c294fc
+      grub_free (data);
c294fc
+      return grub_errno;
c294fc
+    }
c294fc
+
c294fc
   for (i = 0; i < label_len; i++)
c294fc
     {
c294fc
-      catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]);
c294fc
+      label_name[i] = grub_be_to_cpu16 (catkey->name[i]);
c294fc
 
c294fc
       /* If the name is obviously invalid, skip this node.  */
c294fc
-      if (catkey->name[i] == 0)
c294fc
+      if (label_name[i] == 0)
c294fc
 	return 0;
c294fc
     }
c294fc
 
c294fc
-  *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1);
c294fc
+  *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1);
c294fc
   if (! *label)
c294fc
     return grub_errno;
c294fc
 
c294fc
-  *grub_utf16_to_utf8 ((grub_uint8_t *) (*label), catkey->name,
c294fc
+  *grub_utf16_to_utf8 ((grub_uint8_t *) (*label), label_name,
c294fc
 		       label_len) = '\0';
c294fc
 
c294fc
+  grub_free (label_name);
c294fc
   grub_free (node);
c294fc
   grub_free (data);
c294fc
 
c294fc
diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c
c294fc
index c9c8374bf61..092b8f409ec 100644
c294fc
--- a/grub-core/fs/iso9660.c
c294fc
+++ b/grub-core/fs/iso9660.c
c294fc
@@ -331,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_t *us, int len)
c294fc
   int i;
c294fc
   grub_uint16_t t[MAX_NAMELEN / 2 + 1];
c294fc
 
c294fc
-  p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1);
c294fc
+  p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1);
c294fc
   if (! p)
c294fc
     return NULL;
c294fc
 
c294fc
diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c
c294fc
index 6f846886262..9827f9bb8c4 100644
c294fc
--- a/grub-core/fs/ntfs.c
c294fc
+++ b/grub-core/fs/ntfs.c
c294fc
@@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t len)
c294fc
   grub_uint16_t *tmp;
c294fc
   grub_size_t i;
c294fc
 
c294fc
-  buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1);
c294fc
-  tmp = grub_malloc (len * sizeof (tmp[0]));
c294fc
+  buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1);
c294fc
+  tmp = grub_calloc (len, sizeof (tmp[0]));
c294fc
   if (!buf || !tmp)
c294fc
     {
c294fc
       grub_free (buf);
c294fc
diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c
c294fc
index 57b8d8da60b..663931717fd 100644
c294fc
--- a/grub-core/fs/sfs.c
c294fc
+++ b/grub-core/fs/sfs.c
c294fc
@@ -266,7 +266,7 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
c294fc
       node->next_extent = node->block;
c294fc
       node->cache_size = 0;
c294fc
 
c294fc
-      node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size);
c294fc
+      node->cache = grub_calloc (cache_size, sizeof (node->cache[0]));
c294fc
       if (!node->cache)
c294fc
 	{
c294fc
 	  grub_errno = 0;
c294fc
diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c
c294fc
index 39bf197aabe..4864451e19b 100644
c294fc
--- a/grub-core/fs/tar.c
c294fc
+++ b/grub-core/fs/tar.c
c294fc
@@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
c294fc
 	  if (data->linkname_alloc < linksize + 1)
c294fc
 	    {
c294fc
 	      char *n;
c294fc
-	      n = grub_malloc (2 * (linksize + 1));
c294fc
+	      n = grub_calloc (2, linksize + 1);
c294fc
 	      if (!n)
c294fc
 		return grub_errno;
c294fc
 	      grub_free (data->linkname);
c294fc
diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c
c294fc
index 00a16098b47..44481da7c6d 100644
c294fc
--- a/grub-core/fs/udf.c
c294fc
+++ b/grub-core/fs/udf.c
c294fc
@@ -873,7 +873,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf)
c294fc
     {
c294fc
       unsigned i;
c294fc
       utf16len = sz - 1;
c294fc
-      utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
c294fc
+      utf16 = grub_calloc (utf16len, sizeof (utf16[0]));
c294fc
       if (!utf16)
c294fc
 	return NULL;
c294fc
       for (i = 0; i < utf16len; i++)
c294fc
@@ -883,7 +883,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf)
c294fc
     {
c294fc
       unsigned i;
c294fc
       utf16len = (sz - 1) / 2;
c294fc
-      utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
c294fc
+      utf16 = grub_calloc (utf16len, sizeof (utf16[0]));
c294fc
       if (!utf16)
c294fc
 	return NULL;
c294fc
       for (i = 0; i < utf16len; i++)
c294fc
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
c294fc
index 6e1fff9e9ae..f6b95d4fb02 100644
c294fc
--- a/grub-core/fs/zfs/zfs.c
c294fc
+++ b/grub-core/fs/zfs/zfs.c
c294fc
@@ -3325,7 +3325,7 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol,
c294fc
 	}
c294fc
       subvol->nkeys = 0;
c294fc
       zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data);
c294fc
-      subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0]));
c294fc
+      subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0]));
c294fc
       if (!subvol->keyring)
c294fc
 	{
c294fc
 	  grub_free (fsname);
c294fc
@@ -4336,7 +4336,7 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)),
c294fc
   *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS);
c294fc
   if (*nsectors > max_nsectors)
c294fc
     *nsectors = max_nsectors;
c294fc
-  *sectors = grub_malloc (*nsectors * sizeof (**sectors));
c294fc
+  *sectors = grub_calloc (*nsectors, sizeof (**sectors));
c294fc
   if (!*sectors)
c294fc
     return grub_errno;
c294fc
   for (i = 0; i < *nsectors; i++)
c294fc
diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c
c294fc
index a9a415e3129..ba1e1eab319 100644
c294fc
--- a/grub-core/gfxmenu/gui_string_util.c
c294fc
+++ b/grub-core/gfxmenu/gui_string_util.c
c294fc
@@ -55,7 +55,7 @@ canonicalize_path (const char *path)
c294fc
     if (*p == '/')
c294fc
       components++;
c294fc
 
c294fc
-  char **path_array = grub_malloc (components * sizeof (*path_array));
c294fc
+  char **path_array = grub_calloc (components, sizeof (*path_array));
c294fc
   if (! path_array)
c294fc
     return 0;
c294fc
 
c294fc
diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c
c294fc
index b6060288914..470597ded2b 100644
c294fc
--- a/grub-core/gfxmenu/widget-box.c
c294fc
+++ b/grub-core/gfxmenu/widget-box.c
c294fc
@@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix,
c294fc
   box->content_height = 0;
c294fc
   box->raw_pixmaps =
c294fc
     (struct grub_video_bitmap **)
c294fc
-    grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *));
c294fc
+    grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *));
c294fc
   box->scaled_pixmaps =
c294fc
     (struct grub_video_bitmap **)
c294fc
-    grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *));
c294fc
+    grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *));
c294fc
 
c294fc
   /* Initialize all pixmap pointers to NULL so that proper destruction can
c294fc
      be performed if an error is encountered partway through construction.  */
c294fc
diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c
c294fc
index 86ea8cfdea2..7024cda84ea 100644
c294fc
--- a/grub-core/io/gzio.c
c294fc
+++ b/grub-core/io/gzio.c
c294fc
@@ -554,7 +554,7 @@ huft_build (unsigned *b,	/* code lengths in bits (all assumed <= BMAX) */
c294fc
 	      z = 1 << j;	/* table entries for j-bit table */
c294fc
 
c294fc
 	      /* allocate and link in new table */
c294fc
-	      q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft));
c294fc
+	      q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft));
c294fc
 	      if (! q)
c294fc
 		{
c294fc
 		  if (h)
c294fc
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
c294fc
index 4d36fe31177..b1379b92fb8 100644
c294fc
--- a/grub-core/kern/efi/efi.c
c294fc
+++ b/grub-core/kern/efi/efi.c
c294fc
@@ -207,7 +207,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
c294fc
 
c294fc
   len = grub_strlen (var);
c294fc
   len16 = len * GRUB_MAX_UTF16_PER_UTF8;
c294fc
-  var16 = grub_malloc ((len16 + 1) * sizeof (var16[0]));
c294fc
+  var16 = grub_calloc (len16 + 1, sizeof (var16[0]));
c294fc
   if (!var16)
c294fc
     return grub_errno;
c294fc
   len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
c294fc
@@ -242,7 +242,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
c294fc
 
c294fc
   len = grub_strlen (var);
c294fc
   len16 = len * GRUB_MAX_UTF16_PER_UTF8;
c294fc
-  var16 = grub_malloc ((len16 + 1) * sizeof (var16[0]));
c294fc
+  var16 = grub_calloc (len16 + 1, sizeof (var16[0]));
c294fc
   if (!var16)
c294fc
     return NULL;
c294fc
   len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
c294fc
@@ -384,6 +384,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0)
c294fc
 	{
c294fc
 	  grub_efi_file_path_device_path_t *fp;
c294fc
 	  grub_efi_uint16_t len;
c294fc
+	  grub_efi_char16_t *dup_name;
c294fc
 
c294fc
 	  *p++ = '/';
c294fc
 
c294fc
@@ -394,7 +395,16 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0)
c294fc
 	  while (len > 0 && fp->path_name[len - 1] == 0)
c294fc
 	    len--;
c294fc
 
c294fc
-	  p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len);
c294fc
+	  dup_name = grub_calloc (len, sizeof (*dup_name));
c294fc
+	  if (!dup_name)
c294fc
+	    {
c294fc
+	      grub_free (name);
c294fc
+	      return NULL;
c294fc
+	    }
c294fc
+	  p = (char *) grub_utf16_to_utf8 ((unsigned char *) p,
c294fc
+					    grub_memcpy (dup_name, fp->path_name, len * sizeof (*dup_name)),
c294fc
+					    len);
c294fc
+	  grub_free (dup_name);
c294fc
 	}
c294fc
 
c294fc
       dp = GRUB_EFI_NEXT_DEVICE_PATH (dp);
c294fc
@@ -884,9 +894,20 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp)
c294fc
 		fp = (grub_efi_file_path_device_path_t *) dp;
c294fc
 		buf = grub_malloc ((len - 4) * 2 + 1);
c294fc
 		if (buf)
c294fc
-		  *grub_utf16_to_utf8 (buf, fp->path_name,
c294fc
-				       (len - 4) / sizeof (grub_efi_char16_t))
c294fc
-		    = '\0';
c294fc
+		  {
c294fc
+		    grub_efi_char16_t *dup_name = grub_malloc (len - 4);
c294fc
+		    if (!dup_name)
c294fc
+		      {
c294fc
+			grub_errno = GRUB_ERR_NONE;
c294fc
+			grub_printf ("/File((null))");
c294fc
+			grub_free (buf);
c294fc
+			break;
c294fc
+		      }
c294fc
+		    *grub_utf16_to_utf8 (buf, grub_memcpy (dup_name, fp->path_name, len - 4),
c294fc
+					 (len - 4) / sizeof (grub_efi_char16_t))
c294fc
+		      = '\0';
c294fc
+		    grub_free (dup_name);
c294fc
+		  }
c294fc
 		else
c294fc
 		  grub_errno = GRUB_ERR_NONE;
c294fc
 		grub_printf ("/File(%s)", buf);
c294fc
diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c
c294fc
index 87e3e251204..f57bd334c9e 100644
c294fc
--- a/grub-core/kern/emu/hostdisk.c
c294fc
+++ b/grub-core/kern/emu/hostdisk.c
c294fc
@@ -615,7 +615,7 @@ static char *
c294fc
 grub_util_path_concat_real (size_t n, int ext, va_list ap)
c294fc
 {
c294fc
   size_t totlen = 0;
c294fc
-  char **l = xmalloc ((n + ext) * sizeof (l[0]));
c294fc
+  char **l = xcalloc (n + ext, sizeof (l[0]));
c294fc
   char *r, *p, *pi;
c294fc
   size_t i;
c294fc
   int first = 1;
c294fc
diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c
c294fc
index 1bd748be83b..730d21770f2 100644
c294fc
--- a/grub-core/kern/fs.c
c294fc
+++ b/grub-core/kern/fs.c
c294fc
@@ -151,7 +151,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
c294fc
   while (p);
c294fc
 
c294fc
   /* Allocate a block list.  */
c294fc
-  blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1));
c294fc
+  blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block));
c294fc
   if (! blocks)
c294fc
     return 0;
c294fc
 
c294fc
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
c294fc
index aaae9aa0ab7..c034f49f97c 100644
c294fc
--- a/grub-core/kern/misc.c
c294fc
+++ b/grub-core/kern/misc.c
c294fc
@@ -737,7 +737,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args,
c294fc
     args->ptr = args->prealloc;
c294fc
   else
c294fc
     {
c294fc
-      args->ptr = grub_malloc (args->count * sizeof (args->ptr[0]));
c294fc
+      args->ptr = grub_calloc (args->count, sizeof (args->ptr[0]));
c294fc
       if (!args->ptr)
c294fc
 	{
c294fc
 	  grub_errno = GRUB_ERR_NONE;
c294fc
diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c
c294fc
index 78175aac2d3..619db3122a0 100644
c294fc
--- a/grub-core/kern/parser.c
c294fc
+++ b/grub-core/kern/parser.c
c294fc
@@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *cmdline,
c294fc
     return grub_errno;
c294fc
   grub_memcpy (args, buffer, bp - buffer);
c294fc
 
c294fc
-  *argv = grub_malloc (sizeof (char *) * (*argc + 1));
c294fc
+  *argv = grub_calloc (*argc + 1, sizeof (char *));
c294fc
   if (!*argv)
c294fc
     {
c294fc
       grub_free (args);
c294fc
diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c
c294fc
index cf0168e62dd..efa10f2849d 100644
c294fc
--- a/grub-core/kern/uboot/uboot.c
c294fc
+++ b/grub-core/kern/uboot/uboot.c
c294fc
@@ -133,7 +133,7 @@ grub_uboot_dev_enum (void)
c294fc
     return num_devices;
c294fc
 
c294fc
   max_devices = 2;
c294fc
-  enum_devices = grub_malloc (sizeof(struct device_info) * max_devices);
c294fc
+  enum_devices = grub_calloc (max_devices, sizeof(struct device_info));
c294fc
   if (!enum_devices)
c294fc
     return 0;
c294fc
 
c294fc
diff --git a/grub-core/lib/libgcrypt/cipher/ac.c b/grub-core/lib/libgcrypt/cipher/ac.c
c294fc
index f5e946a2d8f..63f6fcd11ef 100644
c294fc
--- a/grub-core/lib/libgcrypt/cipher/ac.c
c294fc
+++ b/grub-core/lib/libgcrypt/cipher/ac.c
c294fc
@@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mpis, unsigned int data_mpis_n,
c294fc
   gcry_mpi_t mpi;
c294fc
   char *label;
c294fc
 
c294fc
-  data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n);
c294fc
+  data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new));
c294fc
   if (! data_mpis_new)
c294fc
     {
c294fc
       err = gcry_error_from_errno (errno);
c294fc
@@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp,
c294fc
     }
c294fc
 
c294fc
   /* Add MPI list.  */
c294fc
-  arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1));
c294fc
+  arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list));
c294fc
   if (! arg_list)
c294fc
     {
c294fc
       err = gcry_error_from_errno (errno);
c294fc
@@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifier, int include_flags,
c294fc
   /* We build a list of arguments to pass to
c294fc
      gcry_sexp_build_array().  */
c294fc
   data_length = _gcry_ac_data_length (data);
c294fc
-  arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2));
c294fc
+  arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2);
c294fc
   if (! arg_list)
c294fc
     {
c294fc
       err = gcry_error_from_errno (errno);
c294fc
@@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits,
c294fc
 	arg_list_n += 2;
c294fc
 
c294fc
   /* Allocate list.  */
c294fc
-  arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n);
c294fc
+  arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list));
c294fc
   if (! arg_list)
c294fc
     {
c294fc
       err = gcry_error_from_errno (errno);
c294fc
diff --git a/grub-core/lib/libgcrypt/cipher/primegen.c b/grub-core/lib/libgcrypt/cipher/primegen.c
c294fc
index 2788e349fa9..b12e79b1922 100644
c294fc
--- a/grub-core/lib/libgcrypt/cipher/primegen.c
c294fc
+++ b/grub-core/lib/libgcrypt/cipher/primegen.c
c294fc
@@ -383,7 +383,7 @@ prime_generate_internal (int need_q_factor,
c294fc
     }
c294fc
 
c294fc
   /* Allocate an array to track pool usage. */
c294fc
-  pool_in_use = gcry_malloc (n * sizeof *pool_in_use);
c294fc
+  pool_in_use = gcry_calloc (n, sizeof *pool_in_use);
c294fc
   if (!pool_in_use)
c294fc
     {
c294fc
       err = gpg_err_code_from_errno (errno);
c294fc
@@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secret, int randomlevel,
c294fc
   if (nbits < 16)
c294fc
     log_fatal ("can't generate a prime with less than %d bits\n", 16);
c294fc
 
c294fc
-  mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods );
c294fc
+  mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods);
c294fc
   /* Make nbits fit into gcry_mpi_t implementation. */
c294fc
   val_2  = mpi_alloc_set_ui( 2 );
c294fc
   val_3 = mpi_alloc_set_ui( 3);
c294fc
diff --git a/grub-core/lib/libgcrypt/cipher/pubkey.c b/grub-core/lib/libgcrypt/cipher/pubkey.c
c294fc
index 910982141e0..ca087ad75b9 100644
c294fc
--- a/grub-core/lib/libgcrypt/cipher/pubkey.c
c294fc
+++ b/grub-core/lib/libgcrypt/cipher/pubkey.c
c294fc
@@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey)
c294fc
        * array to a format string, so we have to do it this way :-(.  */
c294fc
       /* FIXME: There is now such a format specifier, so we can
c294fc
          change the code to be more clear. */
c294fc
-      arg_list = malloc (nelem * sizeof *arg_list);
c294fc
+      arg_list = calloc (nelem, sizeof *arg_list);
c294fc
       if (!arg_list)
c294fc
         {
c294fc
           rc = gpg_err_code_from_syserror ();
c294fc
@@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey)
c294fc
         }
c294fc
       strcpy (p, "))");
c294fc
 
c294fc
-      arg_list = malloc (nelem * sizeof *arg_list);
c294fc
+      arg_list = calloc (nelem, sizeof *arg_list);
c294fc
       if (!arg_list)
c294fc
         {
c294fc
           rc = gpg_err_code_from_syserror ();
c294fc
diff --git a/grub-core/lib/priority_queue.c b/grub-core/lib/priority_queue.c
c294fc
index 659be0b7f40..7d5e7c05aab 100644
c294fc
--- a/grub-core/lib/priority_queue.c
c294fc
+++ b/grub-core/lib/priority_queue.c
c294fc
@@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t elsize,
c294fc
 {
c294fc
   struct grub_priority_queue *ret;
c294fc
   void *els;
c294fc
-  els = grub_malloc (elsize * 8);
c294fc
+  els = grub_calloc (8, elsize);
c294fc
   if (!els)
c294fc
     return 0;
c294fc
   ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret));
c294fc
diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c
c294fc
index ee9fa7b4feb..467305b46ab 100644
c294fc
--- a/grub-core/lib/reed_solomon.c
c294fc
+++ b/grub-core/lib/reed_solomon.c
c294fc
@@ -20,6 +20,7 @@
c294fc
 #include <stdio.h>
c294fc
 #include <string.h>
c294fc
 #include <stdlib.h>
c294fc
+#define xcalloc calloc
c294fc
 #define xmalloc malloc
c294fc
 #define grub_memset memset
c294fc
 #define grub_memcpy memcpy
c294fc
@@ -158,11 +159,9 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs)
c294fc
   gf_single_t *rs_polynomial;
c294fc
   int i, j;
c294fc
   gf_single_t *m;
c294fc
-  m = xmalloc ((s + rs) * sizeof (gf_single_t));
c294fc
+  m = xcalloc (s + rs, sizeof (gf_single_t));
c294fc
   grub_memcpy (m, data, s * sizeof (gf_single_t));
c294fc
-  grub_memset (m + s, 0, rs * sizeof (gf_single_t));
c294fc
-  rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t));
c294fc
-  grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t));
c294fc
+  rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t));
c294fc
   rs_polynomial[rs] = 1;
c294fc
   /* Multiply with X - a^r */
c294fc
   for (j = 0; j < rs; j++)
c294fc
diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
c294fc
index ea3ebc719b1..5847aac3643 100644
c294fc
--- a/grub-core/lib/relocator.c
c294fc
+++ b/grub-core/lib/relocator.c
c294fc
@@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel,
c294fc
   }
c294fc
 #endif
c294fc
 
c294fc
-  eventt = grub_malloc (maxevents * sizeof (events[0]));
c294fc
+  eventt = grub_calloc (maxevents, sizeof (events[0]));
c294fc
   counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0]));
c294fc
-  events = grub_malloc (maxevents * sizeof (events[0]));
c294fc
+  events = grub_calloc (maxevents, sizeof (events[0]));
c294fc
   if (!events || !eventt || !counter)
c294fc
     {
c294fc
       grub_dprintf ("relocator", "events or counter allocation failed %d\n",
c294fc
@@ -963,7 +963,7 @@ malloc_in_range (struct grub_relocator *rel,
c294fc
 #endif
c294fc
     unsigned cural = 0;
c294fc
     int oom = 0;
c294fc
-    res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs);
c294fc
+    res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0]));
c294fc
     if (!res->subchunks)
c294fc
       oom = 1;
c294fc
     res->nsubchunks = nallocs;
c294fc
@@ -1562,8 +1562,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr,
c294fc
 	    count[(chunk->src & 0xff) + 1]++;
c294fc
 	  }
c294fc
     }
c294fc
-    from = grub_malloc (nchunks * sizeof (sorted[0]));
c294fc
-    to = grub_malloc (nchunks * sizeof (sorted[0]));
c294fc
+    from = grub_calloc (nchunks, sizeof (sorted[0]));
c294fc
+    to = grub_calloc (nchunks, sizeof (sorted[0]));
c294fc
     if (!from || !to)
c294fc
       {
c294fc
 	grub_free (from);
c294fc
diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
c294fc
index b4f609d2d01..ea29d7a724a 100644
c294fc
--- a/grub-core/loader/arm/linux.c
c294fc
+++ b/grub-core/loader/arm/linux.c
c294fc
@@ -77,7 +77,7 @@ linux_prepare_atag (void *target_atag)
c294fc
 
c294fc
   /* some place for cmdline, initrd and terminator.  */
c294fc
   tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4;
c294fc
-  tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t));
c294fc
+  tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t));
c294fc
   if (!tmp_atag)
c294fc
     return grub_errno;
c294fc
 
c294fc
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
c294fc
index 3630b0cbf2d..2da119ad513 100644
c294fc
--- a/grub-core/loader/efi/chainloader.c
c294fc
+++ b/grub-core/loader/efi/chainloader.c
c294fc
@@ -119,18 +119,23 @@ static void
c294fc
 copy_file_path (grub_efi_file_path_device_path_t *fp,
c294fc
 		const char *str, grub_efi_uint16_t len)
c294fc
 {
c294fc
-  grub_efi_char16_t *p;
c294fc
+  grub_efi_char16_t *p, *path_name;
c294fc
   grub_efi_uint16_t size;
c294fc
 
c294fc
   fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE;
c294fc
   fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE;
c294fc
 
c294fc
-  size = grub_utf8_to_utf16 (fp->path_name, len * GRUB_MAX_UTF16_PER_UTF8,
c294fc
+  path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name));
c294fc
+  if (!path_name)
c294fc
+    return;
c294fc
+
c294fc
+  size = grub_utf8_to_utf16 (path_name, len * GRUB_MAX_UTF16_PER_UTF8,
c294fc
 			     (const grub_uint8_t *) str, len, 0);
c294fc
-  for (p = fp->path_name; p < fp->path_name + size; p++)
c294fc
+  for (p = path_name; p < path_name + size; p++)
c294fc
     if (*p == '/')
c294fc
       *p = '\\';
c294fc
 
c294fc
+  grub_memcpy (fp->path_name, path_name, size * sizeof (*fp->path_name));
c294fc
   /* File Path is NULL terminated */
c294fc
   fp->path_name[size++] = '\0';
c294fc
   fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp);
c294fc
diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c
c294fc
index af6741d157c..a8d8bf7daed 100644
c294fc
--- a/grub-core/loader/i386/bsdXX.c
c294fc
+++ b/grub-core/loader/i386/bsdXX.c
c294fc
@@ -48,7 +48,7 @@ read_headers (grub_file_t file, const char *filename, Elf_Ehdr *e, char **shdr)
c294fc
   if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS))
c294fc
     return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
c294fc
 
c294fc
-  *shdr = grub_malloc ((grub_uint32_t) e->e_shnum * e->e_shentsize);
c294fc
+  *shdr = grub_calloc (e->e_shnum, e->e_shentsize);
c294fc
   if (! *shdr)
c294fc
     return grub_errno;
c294fc
 
c294fc
diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c
c294fc
index 59ef73a7385..ee0eaadc4ee 100644
c294fc
--- a/grub-core/loader/i386/xnu.c
c294fc
+++ b/grub-core/loader/i386/xnu.c
c294fc
@@ -295,7 +295,7 @@ grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *d
c294fc
     return grub_errno;
c294fc
 
c294fc
   len = grub_strlen (name);
c294fc
-  utf16 = grub_malloc (sizeof (grub_uint16_t) * len);
c294fc
+  utf16 = grub_calloc (len, sizeof (grub_uint16_t));
c294fc
   if (!utf16)
c294fc
     {
c294fc
       grub_free (utf8);
c294fc
@@ -331,7 +331,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor *
c294fc
   grub_uint16_t *utf16;
c294fc
   grub_err_t err;
c294fc
 
c294fc
-  utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen);
c294fc
+  utf16 = grub_calloc (namelen, sizeof (grub_uint16_t));
c294fc
   if (!utf16)
c294fc
     return grub_errno;
c294fc
   grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen);
c294fc
diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c
c294fc
index 59b195e27ea..f61341af515 100644
c294fc
--- a/grub-core/loader/macho.c
c294fc
+++ b/grub-core/loader/macho.c
c294fc
@@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const char *filename, int is_64bit)
c294fc
       if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header))
c294fc
 	  == (grub_off_t) -1)
c294fc
 	goto fail;
c294fc
-      archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs);
c294fc
+      archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch));
c294fc
       if (!archs)
c294fc
 	goto fail;
c294fc
       if (grub_file_read (macho->file, archs,
c294fc
diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
c294fc
index 70cd1db513e..cc6853692a8 100644
c294fc
--- a/grub-core/loader/multiboot_elfxx.c
c294fc
+++ b/grub-core/loader/multiboot_elfxx.c
c294fc
@@ -217,7 +217,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
c294fc
     {
c294fc
       grub_uint8_t *shdr, *shdrptr;
c294fc
 
c294fc
-      shdr = grub_malloc ((grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize);
c294fc
+      shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize);
c294fc
       if (!shdr)
c294fc
 	return grub_errno;
c294fc
       
c294fc
diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c
c294fc
index df8dfdb4ba0..dc7d5409e1e 100644
c294fc
--- a/grub-core/loader/xnu.c
c294fc
+++ b/grub-core/loader/xnu.c
c294fc
@@ -792,7 +792,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
c294fc
   if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC)
c294fc
     {
c294fc
       narchs = grub_be_to_cpu32 (head.nfat_arch);
c294fc
-      archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs);
c294fc
+      archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch));
c294fc
       if (! archs)
c294fc
 	{
c294fc
 	  grub_file_close (file);
c294fc
diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c
c294fc
index 6a31cbae325..57b4e9a72a9 100644
c294fc
--- a/grub-core/mmap/mmap.c
c294fc
+++ b/grub-core/mmap/mmap.c
c294fc
@@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
c294fc
 
c294fc
   /* Initialize variables. */
c294fc
   ctx.scanline_events = (struct grub_mmap_scan *)
c294fc
-    grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num);
c294fc
+    grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2);
c294fc
 
c294fc
-  present = grub_zalloc (sizeof (present[0]) * current_priority);
c294fc
+  present = grub_calloc (current_priority, sizeof (present[0]));
c294fc
 
c294fc
   if (! ctx.scanline_events || !present)
c294fc
     {
c294fc
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
c294fc
index 8b6fc9f2411..adf36fa4a9d 100644
c294fc
--- a/grub-core/net/bootp.c
c294fc
+++ b/grub-core/net/bootp.c
c294fc
@@ -1326,7 +1326,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
c294fc
   if (ncards == 0)
c294fc
     return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found"));
c294fc
 
c294fc
-  ifaces = grub_zalloc (ncards * sizeof (ifaces[0]));
c294fc
+  ifaces = grub_calloc (ncards, sizeof (ifaces[0]));
c294fc
   if (!ifaces)
c294fc
     return grub_errno;
c294fc
 
c294fc
diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c
c294fc
index 5d9afe093c0..e332d5eb4a4 100644
c294fc
--- a/grub-core/net/dns.c
c294fc
+++ b/grub-core/net/dns.c
c294fc
@@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
c294fc
       ptr++;
c294fc
       ptr += 4;
c294fc
     }
c294fc
-  *data->addresses = grub_malloc (sizeof ((*data->addresses)[0])
c294fc
-				 * grub_be_to_cpu16 (head->ancount));
c294fc
+  *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount),
c294fc
+				  sizeof ((*data->addresses)[0]));
c294fc
   if (!*data->addresses)
c294fc
     {
c294fc
       grub_errno = GRUB_ERR_NONE;
c294fc
@@ -406,8 +406,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
c294fc
       dns_cache[h].addresses = 0;
c294fc
       dns_cache[h].name = grub_strdup (data->oname);
c294fc
       dns_cache[h].naddresses = *data->naddresses;
c294fc
-      dns_cache[h].addresses = grub_malloc (*data->naddresses
c294fc
-					    * sizeof (dns_cache[h].addresses[0]));
c294fc
+      dns_cache[h].addresses = grub_calloc (*data->naddresses,
c294fc
+					    sizeof (dns_cache[h].addresses[0]));
c294fc
       dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all;
c294fc
       if (!dns_cache[h].addresses || !dns_cache[h].name)
c294fc
 	{
c294fc
@@ -479,7 +479,7 @@ grub_net_dns_lookup (const char *name,
c294fc
 	}
c294fc
     }
c294fc
 
c294fc
-  sockets = grub_malloc (sizeof (sockets[0]) * n_servers);
c294fc
+  sockets = grub_calloc (n_servers, sizeof (sockets[0]));
c294fc
   if (!sockets)
c294fc
     return grub_errno;
c294fc
 
c294fc
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
c294fc
index 19ff2d486a1..0e72bbb9b39 100644
c294fc
--- a/grub-core/net/net.c
c294fc
+++ b/grub-core/net/net.c
c294fc
@@ -338,8 +338,8 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)),
c294fc
     ncards++;
c294fc
   }
c294fc
 
c294fc
-  ifaces = grub_zalloc (ncards * sizeof (ifaces[0]));
c294fc
-  slaacs = grub_zalloc (ncards * sizeof (slaacs[0]));
c294fc
+  ifaces = grub_calloc (ncards, sizeof (ifaces[0]));
c294fc
+  slaacs = grub_calloc (ncards, sizeof (slaacs[0]));
c294fc
   if (!ifaces || !slaacs)
c294fc
     {
c294fc
       grub_free (ifaces);
c294fc
diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c
c294fc
index b0ab47d73fd..d57fb72faa8 100644
c294fc
--- a/grub-core/normal/charset.c
c294fc
+++ b/grub-core/normal/charset.c
c294fc
@@ -203,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg,
c294fc
 {
c294fc
   grub_size_t msg_len = grub_strlen (msg);
c294fc
 
c294fc
-  *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t));
c294fc
+  *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t));
c294fc
  
c294fc
   if (!*unicode_msg)
c294fc
     return -1;
c294fc
@@ -488,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen,
c294fc
 	    }
c294fc
 	  else
c294fc
 	    {
c294fc
-	      n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1));
c294fc
+	      n = grub_calloc (out->ncomb + 1, sizeof (n[0]));
c294fc
 	      if (!n)
c294fc
 		{
c294fc
 		  grub_errno = GRUB_ERR_NONE;
c294fc
@@ -842,7 +842,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical,
c294fc
       }							\
c294fc
   }
c294fc
 
c294fc
-  visual = grub_malloc (sizeof (visual[0]) * logical_len);
c294fc
+  visual = grub_calloc (logical_len, sizeof (visual[0]));
c294fc
   if (!visual)
c294fc
     return -1;
c294fc
 
c294fc
@@ -1165,8 +1165,8 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical,
c294fc
 {
c294fc
   const grub_uint32_t *line_start = logical, *ptr;
c294fc
   struct grub_unicode_glyph *visual_ptr;
c294fc
-  *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0])
c294fc
-					  * (logical_len + 2));
c294fc
+  *visual_out = visual_ptr = grub_calloc (logical_len + 2,
c294fc
+					  3 * sizeof (visual_ptr[0]));
c294fc
   if (!visual_ptr)
c294fc
     return -1;
c294fc
   for (ptr = logical; ptr <= logical + logical_len; ptr++)
c294fc
diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c
c294fc
index c037d5050ed..c57242e2ea9 100644
c294fc
--- a/grub-core/normal/cmdline.c
c294fc
+++ b/grub-core/normal/cmdline.c
c294fc
@@ -41,7 +41,7 @@ grub_err_t
c294fc
 grub_set_history (int newsize)
c294fc
 {
c294fc
   grub_uint32_t **old_hist_lines = hist_lines;
c294fc
-  hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize);
c294fc
+  hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *));
c294fc
 
c294fc
   /* Copy the old lines into the new buffer.  */
c294fc
   if (old_hist_lines)
c294fc
@@ -114,7 +114,7 @@ static void
c294fc
 grub_history_set (int pos, grub_uint32_t *s, grub_size_t len)
c294fc
 {
c294fc
   grub_free (hist_lines[pos]);
c294fc
-  hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t));
c294fc
+  hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t));
c294fc
   if (!hist_lines[pos])
c294fc
     {
c294fc
       grub_print_error ();
c294fc
@@ -349,7 +349,7 @@ grub_cmdline_get (const char *prompt_translated)
c294fc
   char *ret;
c294fc
   unsigned nterms;
c294fc
 
c294fc
-  buf = grub_malloc (max_len * sizeof (grub_uint32_t));
c294fc
+  buf = grub_calloc (max_len, sizeof (grub_uint32_t));
c294fc
   if (!buf)
c294fc
     return 0;
c294fc
 
c294fc
@@ -377,7 +377,7 @@ grub_cmdline_get (const char *prompt_translated)
c294fc
     FOR_ACTIVE_TERM_OUTPUTS(cur)
c294fc
       nterms++;
c294fc
 
c294fc
-    cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms);
c294fc
+    cl_terms = grub_calloc (nterms, sizeof (cl_terms[0]));
c294fc
     if (!cl_terms)
c294fc
       {
c294fc
 	grub_free (buf);
c294fc
@@ -385,7 +385,7 @@ grub_cmdline_get (const char *prompt_translated)
c294fc
       }
c294fc
     cl_term_cur = cl_terms;
c294fc
 
c294fc
-    unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t));
c294fc
+    unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t));
c294fc
     if (!unicode_msg)
c294fc
       {
c294fc
 	grub_free (buf);
c294fc
@@ -495,7 +495,7 @@ grub_cmdline_get (const char *prompt_translated)
c294fc
 		grub_uint32_t *insert;
c294fc
 
c294fc
 		insertlen = grub_strlen (insertu8);
c294fc
-		insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t));
c294fc
+		insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t));
c294fc
 		if (!insert)
c294fc
 		  {
c294fc
 		    grub_free (insertu8);
c294fc
@@ -602,7 +602,7 @@ grub_cmdline_get (const char *prompt_translated)
c294fc
 
c294fc
 	      grub_free (kill_buf);
c294fc
 
c294fc
-	      kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t));
c294fc
+	      kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t));
c294fc
 	      if (grub_errno)
c294fc
 		{
c294fc
 		  grub_print_error ();
c294fc
diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c
c294fc
index 5785f67ee1c..f31487c1f58 100644
c294fc
--- a/grub-core/normal/menu_entry.c
c294fc
+++ b/grub-core/normal/menu_entry.c
c294fc
@@ -95,8 +95,8 @@ init_line (struct screen *screen, struct line *linep)
c294fc
 {
c294fc
   linep->len = 0;
c294fc
   linep->max_len = 80;
c294fc
-  linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0]));
c294fc
-  linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0]));
c294fc
+  linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0]));
c294fc
+  linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0]));
c294fc
   if (! linep->buf || !linep->pos)
c294fc
     {
c294fc
       grub_free (linep->buf);
c294fc
@@ -287,7 +287,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,
c294fc
 	  pos = linep->pos + (term_screen - screen->terms);
c294fc
 
c294fc
 	  if (!*pos)
c294fc
-	    *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos));
c294fc
+	    *pos = grub_calloc (linep->len + 1, sizeof (**pos));
c294fc
 
c294fc
 	  if (i == region_start || linep == screen->lines + screen->line
c294fc
 	      || (i > region_start && mode == ALL_LINES))
c294fc
@@ -471,7 +471,7 @@ insert_string (struct screen *screen, const char *s, int update)
c294fc
 
c294fc
 	  /* Insert the string.  */
c294fc
 	  current_linep = screen->lines + screen->line;
c294fc
-	  unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t));
c294fc
+	  unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t));
c294fc
 
c294fc
 	  if (!unicode_msg)
c294fc
 	    return 0;
c294fc
@@ -1023,7 +1023,7 @@ complete (struct screen *screen, int continuous, int update)
c294fc
   if (completion_buffer.buf)
c294fc
     {
c294fc
       buflen = grub_strlen (completion_buffer.buf);
c294fc
-      ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1));
c294fc
+      ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t));
c294fc
       
c294fc
       if (!ucs4)
c294fc
 	{
c294fc
@@ -1265,7 +1265,7 @@ grub_menu_entry_run (grub_menu_entry_t entry)
c294fc
   for (i = 0; i < (unsigned) screen->num_lines; i++)
c294fc
     {
c294fc
       grub_free (screen->lines[i].pos);
c294fc
-      screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0]));
c294fc
+      screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0]));
c294fc
       if (! screen->lines[i].pos)
c294fc
 	{
c294fc
 	  grub_print_error ();
c294fc
@@ -1275,7 +1275,7 @@ grub_menu_entry_run (grub_menu_entry_t entry)
c294fc
 	}
c294fc
     }
c294fc
 
c294fc
-  screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0]));
c294fc
+  screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0]));
c294fc
   if (!screen->terms)
c294fc
     {
c294fc
       grub_print_error ();
c294fc
diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c
c294fc
index 7681f7d2893..ca135624356 100644
c294fc
--- a/grub-core/normal/menu_text.c
c294fc
+++ b/grub-core/normal/menu_text.c
c294fc
@@ -78,7 +78,7 @@ grub_print_message_indented_real (const char *msg, int margin_left,
c294fc
   grub_size_t msg_len = grub_strlen (msg) + 2;
c294fc
   int ret = 0;
c294fc
 
c294fc
-  unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t));
c294fc
+  unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t));
c294fc
  
c294fc
   if (!unicode_msg)
c294fc
     return 0;
c294fc
@@ -167,7 +167,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry,
c294fc
 
c294fc
   title = entry ? entry->title : "";
c294fc
   title_len = grub_strlen (title);
c294fc
-  unicode_title = grub_malloc (title_len * sizeof (*unicode_title));
c294fc
+  unicode_title = grub_calloc (title_len, sizeof (*unicode_title));
c294fc
   if (! unicode_title)
c294fc
     /* XXX How to show this error?  */
c294fc
     return;
c294fc
diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c
c294fc
index ac5d69f0fb5..93a3a0d912e 100644
c294fc
--- a/grub-core/normal/term.c
c294fc
+++ b/grub-core/normal/term.c
c294fc
@@ -264,7 +264,7 @@ grub_term_save_pos (void)
c294fc
   FOR_ACTIVE_TERM_OUTPUTS(cur)
c294fc
     cnt++;
c294fc
 
c294fc
-  ret = grub_malloc (cnt * sizeof (ret[0]));
c294fc
+  ret = grub_calloc (cnt, sizeof (ret[0]));
c294fc
   if (!ret)
c294fc
     return NULL;
c294fc
 
c294fc
@@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_t msg_len)
c294fc
 
c294fc
   grub_error_push ();
c294fc
 
c294fc
-  unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t));
c294fc
+  unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t));
c294fc
  
c294fc
   grub_error_pop ();
c294fc
 
c294fc
diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
c294fc
index 388a0f70638..e450f5f0a4c 100644
c294fc
--- a/grub-core/osdep/linux/getroot.c
c294fc
+++ b/grub-core/osdep/linux/getroot.c
c294fc
@@ -176,7 +176,7 @@ grub_util_raid_getmembers (const char *name, int bootable)
c294fc
   if (ret != 0)
c294fc
     grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno));
c294fc
 
c294fc
-  devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *));
c294fc
+  devicelist = xcalloc (info.nr_disks + 1, sizeof (char *));
c294fc
 
c294fc
   for (i = 0, j = 0; j < info.nr_disks; i++)
c294fc
     {
c294fc
@@ -249,7 +249,7 @@ grub_find_root_devices_from_btrfs (const char *dir)
c294fc
       return NULL;
c294fc
     }
c294fc
 
c294fc
-  ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0]));
c294fc
+  ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0]));
c294fc
 
c294fc
   for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++)
c294fc
     {
c294fc
@@ -508,7 +508,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot)
c294fc
   if (relroot)
c294fc
     *relroot = NULL;
c294fc
 
c294fc
-  entries = xmalloc (entry_max * sizeof (*entries));
c294fc
+  entries = xcalloc (entry_max, sizeof (*entries));
c294fc
 
c294fc
 again:
c294fc
   fp = grub_util_fopen ("/proc/self/mountinfo", "r");
c294fc
diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c
c294fc
index b637c58efb7..46a881530c0 100644
c294fc
--- a/grub-core/osdep/unix/config.c
c294fc
+++ b/grub-core/osdep/unix/config.c
c294fc
@@ -102,7 +102,7 @@ grub_util_load_config (struct grub_util_config *cfg)
c294fc
   argv[0] = "sh";
c294fc
   argv[1] = "-c";
c294fc
 
c294fc
-  script = xmalloc (4 * strlen (cfgfile) + 300);
c294fc
+  script = xcalloc (4, strlen (cfgfile) + 300);
c294fc
 
c294fc
   ptr = script;
c294fc
   memcpy (ptr, ". '", 3);
c294fc
diff --git a/grub-core/osdep/windows/getroot.c b/grub-core/osdep/windows/getroot.c
c294fc
index 661d9546192..eada663b261 100644
c294fc
--- a/grub-core/osdep/windows/getroot.c
c294fc
+++ b/grub-core/osdep/windows/getroot.c
c294fc
@@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path)
c294fc
 
c294fc
   for (ptr = path; *ptr; ptr++);
c294fc
   allocsize = (ptr - path + 10) * 2;
c294fc
-  out = xmalloc (allocsize * sizeof (out[0]));
c294fc
+  out = xcalloc (allocsize, sizeof (out[0]));
c294fc
 
c294fc
   /* When pointing to EFI system partition GetVolumePathName fails
c294fc
      for ESP root and returns abberant information for everything
c294fc
diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c
c294fc
index 6f49df465d7..580b3f2dae7 100644
c294fc
--- a/grub-core/osdep/windows/hostdisk.c
c294fc
+++ b/grub-core/osdep/windows/hostdisk.c
c294fc
@@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const char *path)
c294fc
 
c294fc
   while (1)
c294fc
     {
c294fc
-      fpa = xmalloc (alloc * sizeof (fpa[0]));
c294fc
+      fpa = xcalloc (alloc, sizeof (fpa[0]));
c294fc
 
c294fc
       len = GetFullPathName (tpath, alloc, fpa, NULL);
c294fc
       if (len >= alloc)
c294fc
@@ -393,7 +393,7 @@ grub_util_fd_opendir (const char *name)
c294fc
   for (l = 0; name_windows[l]; l++);
c294fc
   for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--);
c294fc
   l++;
c294fc
-  pattern = xmalloc ((l + 3) * sizeof (pattern[0]));
c294fc
+  pattern = xcalloc (l + 3, sizeof (pattern[0]));
c294fc
   memcpy (pattern, name_windows, l * sizeof (pattern[0]));
c294fc
   pattern[l] = '\\';
c294fc
   pattern[l + 1] = '*';
c294fc
diff --git a/grub-core/osdep/windows/init.c b/grub-core/osdep/windows/init.c
c294fc
index e8ffd62c6a0..6297de6326a 100644
c294fc
--- a/grub-core/osdep/windows/init.c
c294fc
+++ b/grub-core/osdep/windows/init.c
c294fc
@@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)),
c294fc
   LPWSTR *targv;
c294fc
 
c294fc
   targv = CommandLineToArgvW (tcmdline, argc);
c294fc
-  *argv = xmalloc ((*argc + 1) * sizeof (argv[0]));
c294fc
+  *argv = xcalloc (*argc + 1, sizeof (argv[0]));
c294fc
 
c294fc
   for (i = 0; i < *argc; i++)
c294fc
     (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); 
c294fc
diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c
c294fc
index 912269191eb..04e0eda9aeb 100644
c294fc
--- a/grub-core/osdep/windows/platform.c
c294fc
+++ b/grub-core/osdep/windows/platform.c
c294fc
@@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
c294fc
     grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode"));
c294fc
 
c294fc
   distrib8_len = grub_strlen (efi_distributor);
c294fc
-  distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8
c294fc
-			   * sizeof (grub_uint16_t));
c294fc
+  distributor16 = xcalloc (distrib8_len + 1,
c294fc
+			   GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t));
c294fc
   distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8,
c294fc
 				      (const grub_uint8_t *) efi_distributor,
c294fc
 				      distrib8_len, 0);
c294fc
diff --git a/grub-core/osdep/windows/relpath.c b/grub-core/osdep/windows/relpath.c
c294fc
index cb0861744ae..478e8ef14d5 100644
c294fc
--- a/grub-core/osdep/windows/relpath.c
c294fc
+++ b/grub-core/osdep/windows/relpath.c
c294fc
@@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_root (const char *path)
c294fc
       if (dirwindows[0] && dirwindows[1] == ':')
c294fc
 	offset = 2;
c294fc
     }
c294fc
-  ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2));
c294fc
+  ret = xcalloc (flen - offset + 2, sizeof (ret[0]));
c294fc
   if (dirwindows[offset] != '\\'
c294fc
       && dirwindows[offset] != '/'
c294fc
       && dirwindows[offset])
c294fc
diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c
c294fc
index 103f6796f39..72a2e37cd48 100644
c294fc
--- a/grub-core/partmap/gpt.c
c294fc
+++ b/grub-core/partmap/gpt.c
c294fc
@@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
c294fc
   *nsectors = ctx.len;
c294fc
   if (*nsectors > max_nsectors)
c294fc
     *nsectors = max_nsectors;
c294fc
-  *sectors = grub_malloc (*nsectors * sizeof (**sectors));
c294fc
+  *sectors = grub_calloc (*nsectors, sizeof (**sectors));
c294fc
   if (!*sectors)
c294fc
     return grub_errno;
c294fc
   for (i = 0; i < *nsectors; i++)
c294fc
diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c
c294fc
index 6d4b455a19c..81ca6b90e67 100644
c294fc
--- a/grub-core/partmap/msdos.c
c294fc
+++ b/grub-core/partmap/msdos.c
c294fc
@@ -337,7 +337,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
c294fc
       avail_nsectors = *nsectors;
c294fc
       if (*nsectors > max_nsectors)
c294fc
 	*nsectors = max_nsectors;
c294fc
-      *sectors = grub_malloc (*nsectors * sizeof (**sectors));
c294fc
+      *sectors = grub_calloc (*nsectors, sizeof (**sectors));
c294fc
       if (!*sectors)
c294fc
 	return grub_errno;
c294fc
       for (i = 0; i < *nsectors; i++)
c294fc
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
c294fc
index 7d327f59d92..528ddfd36f0 100644
c294fc
--- a/grub-core/script/execute.c
c294fc
+++ b/grub-core/script/execute.c
c294fc
@@ -587,7 +587,7 @@ gettext_append (struct grub_script_argv *result, const char *orig_str)
c294fc
   for (iptr = orig_str; *iptr; iptr++)
c294fc
     if (*iptr == '$')
c294fc
       dollar_cnt++;
c294fc
-  ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt);
c294fc
+  ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0]));
c294fc
 
c294fc
   if (parse_string (orig_str, gettext_save_allow, &ctx, 0))
c294fc
     goto fail;
c294fc
diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c
c294fc
index 2d60852989c..b5eb516be2d 100644
c294fc
--- a/grub-core/tests/fake_input.c
c294fc
+++ b/grub-core/tests/fake_input.c
c294fc
@@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int *seq_in, int nseq_in)
c294fc
     saved = grub_term_inputs;
c294fc
   if (seq)
c294fc
     grub_free (seq);
c294fc
-  seq = grub_malloc (nseq_in * sizeof (seq[0]));
c294fc
+  seq = grub_calloc (nseq_in, sizeof (seq[0]));
c294fc
   if (!seq)
c294fc
     return;
c294fc
 
c294fc
diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c
c294fc
index 74d5b65e5c7..44d0810698a 100644
c294fc
--- a/grub-core/tests/video_checksum.c
c294fc
+++ b/grub-core/tests/video_checksum.c
c294fc
@@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char *fname,
c294fc
     {
c294fc
     case 4:
c294fc
       {
c294fc
-	grub_uint8_t *buffer = xmalloc (mode_info->width * 3);
c294fc
+	grub_uint8_t *buffer = xcalloc (3, mode_info->width);
c294fc
 	grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1);
c294fc
 	grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1);
c294fc
 	grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1);
c294fc
@@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char *fname,
c294fc
       }
c294fc
     case 3:
c294fc
       {
c294fc
-	grub_uint8_t *buffer = xmalloc (mode_info->width * 3);
c294fc
+	grub_uint8_t *buffer = xcalloc (3, mode_info->width);
c294fc
 	grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1);
c294fc
 	grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1);
c294fc
 	grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1);
c294fc
@@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char *fname,
c294fc
       }
c294fc
     case 2:
c294fc
       {
c294fc
-	grub_uint8_t *buffer = xmalloc (mode_info->width * 3);
c294fc
+	grub_uint8_t *buffer = xcalloc (3, mode_info->width);
c294fc
 	grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1);
c294fc
 	grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1);
c294fc
 	grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1);
c294fc
diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c
c294fc
index 4f83c744116..4d3195e017b 100644
c294fc
--- a/grub-core/video/capture.c
c294fc
+++ b/grub-core/video/capture.c
c294fc
@@ -89,7 +89,7 @@ grub_video_capture_start (const struct grub_video_mode_info *mode_info,
c294fc
   framebuffer.mode_info = *mode_info;
c294fc
   framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info);
c294fc
 
c294fc
-  framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch);
c294fc
+  framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch);
c294fc
   if (!framebuffer.ptr)
c294fc
     return grub_errno;
c294fc
   
c294fc
diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c
c294fc
index a2f639f66de..0ebab6f57dd 100644
c294fc
--- a/grub-core/video/emu/sdl.c
c294fc
+++ b/grub-core/video/emu/sdl.c
c294fc
@@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count,
c294fc
       if (start + count > mode_info.number_of_colors)
c294fc
 	count = mode_info.number_of_colors - start;
c294fc
 
c294fc
-      tmp = grub_malloc (count * sizeof (tmp[0]));
c294fc
+      tmp = grub_calloc (count, sizeof (tmp[0]));
c294fc
       for (i = 0; i < count; i++)
c294fc
 	{
c294fc
 	  tmp[i].r = palette_data[i].r;
c294fc
diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c
c294fc
index 01f47112d37..b2f776c997b 100644
c294fc
--- a/grub-core/video/i386/pc/vga.c
c294fc
+++ b/grub-core/video/i386/pc/vga.c
c294fc
@@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width, unsigned int height,
c294fc
 
c294fc
   vga_height = height ? : 480;
c294fc
 
c294fc
-  framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH);
c294fc
+  framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH);
c294fc
   framebuffer.front_page = 0;
c294fc
   framebuffer.back_page = 0;
c294fc
   if (!framebuffer.temporary_buffer)
c294fc
diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c
c294fc
index e1a01e99fd0..e85df3c1b04 100644
c294fc
--- a/grub-core/video/readers/png.c
c294fc
+++ b/grub-core/video/readers/png.c
c294fc
@@ -309,7 +309,7 @@ grub_png_decode_image_header (struct grub_png_data *data)
c294fc
   if (data->is_16bit || data->is_gray || data->is_palette)
c294fc
 #endif
c294fc
     {
c294fc
-      data->image_data = grub_malloc (data->image_height * data->row_bytes);
c294fc
+      data->image_data = grub_calloc (data->image_height, data->row_bytes);
c294fc
       if (grub_errno)
c294fc
         return grub_errno;
c294fc
 
c294fc
diff --git a/util/getroot.c b/util/getroot.c
c294fc
index fa3460d6cd8..6feb2a4de40 100644
c294fc
--- a/util/getroot.c
c294fc
+++ b/util/getroot.c
c294fc
@@ -219,7 +219,7 @@ make_device_name (const char *drive)
c294fc
   char *ret, *ptr;
c294fc
   const char *iptr;
c294fc
 
c294fc
-  ret = xmalloc (strlen (drive) * 2);
c294fc
+  ret = xcalloc (2, strlen (drive));
c294fc
   ptr = ret;
c294fc
   for (iptr = drive; *iptr; iptr++)
c294fc
     {
c294fc
diff --git a/util/grub-file.c b/util/grub-file.c
c294fc
index 50c18b6835a..b2e7dd69f4c 100644
c294fc
--- a/util/grub-file.c
c294fc
+++ b/util/grub-file.c
c294fc
@@ -54,7 +54,7 @@ main (int argc, char *argv[])
c294fc
 
c294fc
   grub_util_host_init (&argc, &argv);
c294fc
 
c294fc
-  argv2 = xmalloc (argc * sizeof (argv2[0]));
c294fc
+  argv2 = xcalloc (argc, sizeof (argv2[0]));
c294fc
 
c294fc
   if (argc == 2 && strcmp (argv[1], "--version") == 0)
c294fc
     {
c294fc
diff --git a/util/grub-fstest.c b/util/grub-fstest.c
c294fc
index a358ae47152..793aefa02b1 100644
c294fc
--- a/util/grub-fstest.c
c294fc
+++ b/util/grub-fstest.c
c294fc
@@ -650,7 +650,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
c294fc
   if (args_count < num_disks)
c294fc
     {
c294fc
       if (args_count == 0)
c294fc
-	images = xmalloc (num_disks * sizeof (images[0]));
c294fc
+	images = xcalloc (num_disks, sizeof (images[0]));
c294fc
       images[args_count] = grub_canonicalize_file_name (arg);
c294fc
       args_count++;
c294fc
       return 0;
c294fc
@@ -734,7 +734,7 @@ main (int argc, char *argv[])
c294fc
 
c294fc
   grub_util_host_init (&argc, &argv);
c294fc
 
c294fc
-  args = xmalloc (argc * sizeof (args[0]));
c294fc
+  args = xcalloc (argc, sizeof (args[0]));
c294fc
 
c294fc
   argp_parse (&argp, argc, argv, 0, 0, 0);
c294fc
 
c294fc
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
c294fc
index 0a2e24a79f1..cf993c059ad 100644
c294fc
--- a/util/grub-install-common.c
c294fc
+++ b/util/grub-install-common.c
c294fc
@@ -281,7 +281,7 @@ handle_install_list (struct install_list *il, const char *val,
c294fc
       il->n_entries++;
c294fc
     }
c294fc
   il->n_alloc = il->n_entries + 1;
c294fc
-  il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0]));
c294fc
+  il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0]));
c294fc
   ptr = val;
c294fc
   for (ce = il->entries; ; ce++)
c294fc
     {
c294fc
diff --git a/util/grub-install.c b/util/grub-install.c
c294fc
index 16f137ca854..3bf0e063a86 100644
c294fc
--- a/util/grub-install.c
c294fc
+++ b/util/grub-install.c
c294fc
@@ -623,7 +623,7 @@ device_map_check_duplicates (const char *dev_map)
c294fc
   if (! fp)
c294fc
     return;
c294fc
 
c294fc
-  d = xmalloc (alloced * sizeof (d[0]));
c294fc
+  d = xcalloc (alloced, sizeof (d[0]));
c294fc
 
c294fc
   while (fgets (buf, sizeof (buf), fp))
c294fc
     {
c294fc
@@ -1232,7 +1232,7 @@ main (int argc, char *argv[])
c294fc
       ndev++;
c294fc
     }
c294fc
 
c294fc
-  grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); 
c294fc
+  grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0]));
c294fc
 
c294fc
   for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++,
c294fc
        curdrive++)
c294fc
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
c294fc
index a483c674c49..f9aa1a033b5 100644
c294fc
--- a/util/grub-mkimagexx.c
c294fc
+++ b/util/grub-mkimagexx.c
c294fc
@@ -1999,10 +1999,8 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path,
c294fc
 		      + grub_host_to_target16 (e->e_shstrndx) * smd.section_entsize);
c294fc
   smd.strtab = (char *) e + grub_host_to_target_addr (s->sh_offset);
c294fc
 
c294fc
-  smd.addrs = xmalloc (sizeof (*smd.addrs) * smd.num_sections);
c294fc
-  memset (smd.addrs, 0, sizeof (*smd.addrs) * smd.num_sections);
c294fc
-  smd.vaddrs = xmalloc (sizeof (*smd.vaddrs) * smd.num_sections);
c294fc
-  memset (smd.vaddrs, 0, sizeof (*smd.vaddrs) * smd.num_sections);
c294fc
+  smd.addrs = xcalloc (smd.num_sections, sizeof (*smd.addrs));
c294fc
+  smd.vaddrs = xcalloc (smd.num_sections, sizeof (*smd.vaddrs));
c294fc
 
c294fc
   SUFFIX (locate_sections) (e, kernel_path, &smd, layout, image_target);
c294fc
 
c294fc
diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c
c294fc
index 9545945d8f3..21e72bde474 100644
c294fc
--- a/util/grub-mkrescue.c
c294fc
+++ b/util/grub-mkrescue.c
c294fc
@@ -441,8 +441,8 @@ main (int argc, char *argv[])
c294fc
   xorriso = xstrdup ("xorriso");
c294fc
   label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2");
c294fc
 
c294fc
-  argp_argv = xmalloc (sizeof (argp_argv[0]) * argc);
c294fc
-  xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc);
c294fc
+  argp_argv = xcalloc (argc, sizeof (argp_argv[0]));
c294fc
+  xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0]));
c294fc
 
c294fc
   xorriso_tail_argc = 0;
c294fc
   /* Program name */
c294fc
diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c
c294fc
index 4907d44c0bd..edf309717c3 100644
c294fc
--- a/util/grub-mkstandalone.c
c294fc
+++ b/util/grub-mkstandalone.c
c294fc
@@ -296,7 +296,7 @@ main (int argc, char *argv[])
c294fc
   grub_util_host_init (&argc, &argv);
c294fc
   grub_util_disable_fd_syncs ();
c294fc
 
c294fc
-  files = xmalloc ((argc + 1) * sizeof (files[0]));
c294fc
+  files = xcalloc (argc + 1, sizeof (files[0]));
c294fc
 
c294fc
   argp_parse (&argp, argc, argv, 0, 0, 0);
c294fc
 
c294fc
diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c
c294fc
index 0d4084a108e..11331294f1b 100644
c294fc
--- a/util/grub-pe2elf.c
c294fc
+++ b/util/grub-pe2elf.c
c294fc
@@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char *name, char *image,
c294fc
   char *pe_strtab = (image + pe_chdr->symtab_offset
c294fc
 		     + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol));
c294fc
 
c294fc
-  section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int));
c294fc
+  section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int));
c294fc
   section_map[0] = 0;
c294fc
-  shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0]));
c294fc
+  shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0]));
c294fc
   idx = 1;
c294fc
   idx_reloc = pe_chdr->num_sections + 1;
c294fc
 
c294fc
@@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const char *name, char *image,
c294fc
 
c294fc
       pe_sec = pe_shdr + shdr[i].sh_link;
c294fc
       pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset);
c294fc
-      rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t));
c294fc
+      rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t));
c294fc
       num_rels = 0;
c294fc
       modified = 0;
c294fc
 
c294fc
@@ -365,12 +365,10 @@ write_symbol_table (FILE* fp, const char *name, char *image,
c294fc
   pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset);
c294fc
   pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols);
c294fc
 
c294fc
-  symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) *
c294fc
-				sizeof (Elf_Sym));
c294fc
-  memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym));
c294fc
+  symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym));
c294fc
   num_syms = 1;
c294fc
 
c294fc
-  symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int));
c294fc
+  symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int));
c294fc
 
c294fc
   for (i = 0; i < (int) pe_chdr->num_symbols;
c294fc
        i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1)
c294fc
diff --git a/util/grub-probe.c b/util/grub-probe.c
c294fc
index e45dbf9e049..2a8c2cdffd5 100644
c294fc
--- a/util/grub-probe.c
c294fc
+++ b/util/grub-probe.c
c294fc
@@ -361,8 +361,8 @@ probe (const char *path, char **device_names, char delim)
c294fc
       grub_util_pull_device (*curdev);
c294fc
       ndev++;
c294fc
     }
c294fc
-  
c294fc
-  drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); 
c294fc
+
c294fc
+  drives_names = xcalloc (ndev + 1, sizeof (drives_names[0]));
c294fc
 
c294fc
   for (curdev = device_names, curdrive = drives_names; *curdev; curdev++,
c294fc
        curdrive++)
c294fc
diff --git a/include/grub/unicode.h b/include/grub/unicode.h
c294fc
index a0403e91f9a..4de986a8576 100644
c294fc
--- a/include/grub/unicode.h
c294fc
+++ b/include/grub/unicode.h
c294fc
@@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in)
c294fc
   grub_memcpy (out, in, sizeof (*in));
c294fc
   if (in->ncomb > ARRAY_SIZE (out->combining_inline))
c294fc
     {
c294fc
-      out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0]));
c294fc
+      out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0]));
c294fc
       if (!out->combining_ptr)
c294fc
 	{
c294fc
 	  grub_free (out);
c294fc
@@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unicode_glyph *out,
c294fc
   grub_memcpy (out, in, sizeof (*in));
c294fc
   if (in->ncomb > ARRAY_SIZE (out->combining_inline))
c294fc
     {
c294fc
-      out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0]));
c294fc
+      out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0]));
c294fc
       if (!out->combining_ptr)
c294fc
 	return;
c294fc
       grub_memcpy (out->combining_ptr, in->combining_ptr,
c294fc
-- 
c294fc
2.26.2
c294fc