dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0293-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch

5975ab
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a4d572
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
a4d572
Date: Fri, 26 Jun 2020 10:51:43 -0400
5975ab
Subject: [PATCH] multiboot2: Fix memory leak if grub_create_loader_cmdline()
5975ab
 fails
a4d572
a4d572
Fixes: CID 292468
a4d572
a4d572
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
a4d572
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
a4d572
Upstream-commit-id: cd6760b6289
a4d572
---
a4d572
 grub-core/loader/multiboot_mbi2.c | 11 +++++++++--
a4d572
 1 file changed, 9 insertions(+), 2 deletions(-)
a4d572
a4d572
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
a4d572
index 54078455e2f..872dcd42e97 100644
a4d572
--- a/grub-core/loader/multiboot_mbi2.c
a4d572
+++ b/grub-core/loader/multiboot_mbi2.c
a4d572
@@ -1089,6 +1089,7 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size,
a4d572
 {
a4d572
   struct module *newmod;
a4d572
   grub_size_t len = 0;
a4d572
+  grub_err_t err = 0;
a4d572
 
a4d572
   newmod = grub_malloc (sizeof (*newmod));
a4d572
   if (!newmod)
a4d572
@@ -1107,8 +1108,14 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size,
a4d572
   newmod->cmdline_size = len;
a4d572
   total_modcmd += ALIGN_UP (len, MULTIBOOT_TAG_ALIGN);
a4d572
 
a4d572
-  grub_create_loader_cmdline (argc, argv, newmod->cmdline,
a4d572
-			      newmod->cmdline_size);
a4d572
+  err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
a4d572
+				    newmod->cmdline_size);
a4d572
+  if (err)
a4d572
+    {
a4d572
+      grub_free (newmod->cmdline);
a4d572
+      grub_free (newmod);
a4d572
+      return err;
a4d572
+    }
a4d572
 
a4d572
   if (modules_last)
a4d572
     modules_last->next = newmod;