From: Daniel Axtens Date: Sun, 21 Aug 2022 12:22:35 +0000 (+1000) Subject: disk/diskfilter: Check calloc() result for NULL X-Git-Tag: grub-2.12-rc1~253 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=12e20a6a695f4967b30a95bb52e4e2e0a10c9094;p=thirdparty%2Fgrub.git disk/diskfilter: Check calloc() result for NULL With wildly corrupt inputs, we can end up trying to calloc a very large amount of memory, which will fail and give us a NULL pointer. We need to check that to avoid a crash. (And, even if we blocked such inputs, it is good practice to check the results of allocations anyway.) Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c index 2edcff6e8..4ac50320e 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -1163,6 +1163,9 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, array->lvs->segments->raid_member_size = disk_size; array->lvs->segments->nodes = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); + if (array->lvs->segments->nodes == NULL) + goto fail; + array->lvs->segments->stripe_size = stripe_size; for (i = 0; i < nmemb; i++) {