dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0327-efi-dhcp-fix-some-allocation-error-checking.patch

b1bcb2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
c4e390
From: Peter Jones <pjones@redhat.com>
c4e390
Date: Sun, 19 Jul 2020 17:11:06 -0400
b1bcb2
Subject: [PATCH] efi+dhcp: fix some allocation error checking.
c4e390
c4e390
Signed-off-by: Peter Jones <pjones@redhat.com>
c4e390
---
c4e390
 grub-core/net/efi/dhcp.c | 9 ++++++---
c4e390
 1 file changed, 6 insertions(+), 3 deletions(-)
c4e390
c4e390
diff --git a/grub-core/net/efi/dhcp.c b/grub-core/net/efi/dhcp.c
c4e390
index dbef63d8c08..e5c79b748b0 100644
c4e390
--- a/grub-core/net/efi/dhcp.c
c4e390
+++ b/grub-core/net/efi/dhcp.c
c4e390
@@ -80,7 +80,7 @@ grub_efi_dhcp4_parse_dns (grub_efi_dhcp4_protocol_t *dhcp4, grub_efi_dhcp4_packe
c4e390
   if (status != GRUB_EFI_BUFFER_TOO_SMALL)
c4e390
     return NULL;
c4e390
 
c4e390
-  option_list = grub_malloc (option_count * sizeof(*option_list));
c4e390
+  option_list = grub_calloc (option_count, sizeof(*option_list));
c4e390
   if (!option_list)
c4e390
     return NULL;
c4e390
 
c4e390
@@ -360,8 +360,11 @@ grub_cmd_efi_bootp6 (struct grub_command *cmd __attribute__ ((unused)),
c4e390
 
c4e390
 	if (status == GRUB_EFI_BUFFER_TOO_SMALL && count)
c4e390
 	  {
c4e390
-	    options = grub_malloc (count * sizeof(*options));
c4e390
-	    status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options);
c4e390
+	    options = grub_calloc (count, sizeof(*options));
c4e390
+	    if (options)
c4e390
+	      status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options);
c4e390
+	    else
c4e390
+	      status = GRUB_EFI_OUT_OF_RESOURCES;
c4e390
 	  }
c4e390
 
c4e390
 	if (status != GRUB_EFI_SUCCESS)