2
1

0046-disk-Prevent-overflows-when-allocating-memory-for-ar.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. From d9f900247eb886176aace7888be941348a9c8fc8 Mon Sep 17 00:00:00 2001
  2. From: Alec Brown <alec.r.brown@oracle.com>
  3. Date: Wed, 22 Jan 2025 02:55:10 +0000
  4. Subject: [PATCH] disk: Prevent overflows when allocating memory for arrays
  5. Use grub_calloc() when allocating memory for arrays to ensure proper
  6. overflow checks are in place.
  7. Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
  8. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  9. Conflicts:
  10. grub-core/disk/cryptodisk.c
  11. Upstream: d8151f98331ee4d15fcca59edffa59246d8fc15f
  12. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  13. ---
  14. grub-core/disk/lvm.c | 6 ++----
  15. 1 file changed, 2 insertions(+), 4 deletions(-)
  16. diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c
  17. index 794248540..a395b200d 100644
  18. --- a/grub-core/disk/lvm.c
  19. +++ b/grub-core/disk/lvm.c
  20. @@ -671,8 +671,7 @@ grub_lvm_detect (grub_disk_t disk,
  21. goto lvs_segment_fail;
  22. }
  23. - seg->nodes = grub_zalloc (sizeof (seg->nodes[0])
  24. - * seg->node_count);
  25. + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0]));
  26. p = grub_strstr (p, "mirrors = [");
  27. if (p == NULL)
  28. @@ -760,8 +759,7 @@ grub_lvm_detect (grub_disk_t disk,
  29. }
  30. }
  31. - seg->nodes = grub_zalloc (sizeof (seg->nodes[0])
  32. - * seg->node_count);
  33. + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0]));
  34. p = grub_strstr (p, "raids = [");
  35. if (p == NULL)
  36. --
  37. 2.50.1