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