From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Lidong Chen Date: Wed, 22 Jan 2025 07:17:03 +0000 Subject: [PATCH] fs/zfs: Prevent overflows when allocating memory for arrays Use grub_calloc() when allocating memory for arrays to ensure proper overflow checks are in place. Signed-off-by: Lidong Chen Reviewed-by: Daniel Kiper --- grub-core/fs/zfs/zfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 4384d6aae..23fe50211 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -717,9 +717,9 @@ fill_vdev_info_real (struct grub_zfs_data *data, if (!fill->children) { fill->n_children = nelm; - - fill->children = grub_zalloc (fill->n_children - * sizeof (fill->children[0])); + + fill->children = grub_calloc (fill->n_children, + sizeof (fill->children[0])); } for (i = 0; i < nelm; i++) @@ -3693,8 +3693,8 @@ zfs_mount (grub_device_t dev) #endif data->n_devices_allocated = 16; - data->devices_attached = grub_malloc (sizeof (data->devices_attached[0]) - * data->n_devices_allocated); + data->devices_attached = grub_calloc (data->n_devices_allocated, + sizeof (data->devices_attached[0])); data->n_devices_attached = 0; err = scan_disk (dev, data, 1, &inserted); if (err)