Skip to contentSkip to conversation

efi_loader: handle malloc() errors

PATCH In review Vincent Stehlé 2 participants 2 messages Apr 1, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: handle malloc() errors

The new_packagelist() function of the HII Protocols implementation is calling malloc() without checking its return code; fix this.

Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
---
 lib/efi_loader/efi_hii.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/efi_hii.c +3 -0
index 44235970a7c..330d7c5830b 100644
@@ -343,6 +343,9 @@ static struct efi_hii_packagelist *new_packagelist(void)
 	struct efi_hii_packagelist *hii;
 
 	hii = malloc(sizeof(*hii));
+	if (!hii)
+		return NULL;
+
 	list_add_tail(&hii->link, &efi_package_lists);
 	hii->max_string_id = 0;
 	INIT_LIST_HEAD(&hii->string_tables);
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Vincent Stehlé

The new_packagelist() function of the HII Protocols implementation is calling malloc() without checking its return code; fix this.

Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
---
 lib/efi_loader/efi_hii.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/efi_hii.c +3 -1
index 44235970a7c..330d7c5830b 100644
@@ -343,6 +343,9 @@ static struct efi_hii_packagelist *new_packagelist(void)
        struct efi_hii_packagelist *hii;
 
        hii = malloc(sizeof(*hii));
+       if (!hii)
+               return NULL;
+
        list_add_tail(&hii->link, &efi_package_lists);
        hii->max_string_id = 0;
        INIT_LIST_HEAD(&hii->string_tables);
--
Quoted 2 lines

2.47.2