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 <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Daniel Axtens 2022-08-21 22:22:35 +10:00 committed by Daniel Kiper
parent 3cf2e848bc
commit 12e20a6a69

View File

@ -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++)
{