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