nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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