From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Alec Brown Date: Wed, 22 Jan 2025 02:55:10 +0000 Subject: [PATCH] disk: 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: Alec Brown Reviewed-by: Daniel Kiper --- grub-core/disk/lvm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 7e86bb7df..47a89e6d0 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -634,8 +634,7 @@ error_parsing_metadata: goto lvs_segment_fail; } - seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) - * seg->node_count); + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); p = grub_strstr (p, "mirrors = ["); if (p == NULL) @@ -723,8 +722,7 @@ error_parsing_metadata: } } - seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) - * seg->node_count); + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); p = grub_strstr (p, "raids = ["); if (p == NULL)