]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
disk/diskfilter: Check calloc() result for NULL
authorDaniel Axtens <dja@axtens.net>
Sun, 21 Aug 2022 12:22:35 +0000 (22:22 +1000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 11 Oct 2022 12:49:39 +0000 (14:49 +0200)
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>
grub-core/disk/diskfilter.c

index 2edcff6e8987a9300a82d97d564b7ee2a0ec440d..4ac50320ef4e8832556a096d1bc62e9784bfa106 100644 (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++)
     {