nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0413-normal-completion-Fix-leaking-of-memory-when-process.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Darren Kenny <darren.kenny@oracle.com>
9723a8
Date: Fri, 4 Dec 2020 18:56:48 +0000
9723a8
Subject: [PATCH] normal/completion: Fix leaking of memory when processing a
9723a8
 completion
9723a8
9723a8
It is possible for the code to reach the end of the function without
9723a8
freeing the memory allocated to argv and argc still to be 0.
9723a8
9723a8
We should always call grub_free(argv). The grub_free() will handle
9723a8
a NULL argument correctly if it reaches that code without the memory
9723a8
being allocated.
9723a8
9723a8
Fixes: CID 96672
9723a8
9723a8
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/normal/completion.c | 10 ++++------
9723a8
 1 file changed, 4 insertions(+), 6 deletions(-)
9723a8
9723a8
diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c
b71686
index 93aa0d8ed..5036bcf2d 100644
9723a8
--- a/grub-core/normal/completion.c
9723a8
+++ b/grub-core/normal/completion.c
9723a8
@@ -401,8 +401,8 @@ char *
9723a8
 grub_normal_do_completion (char *buf, int *restore,
9723a8
 			   void (*hook) (const char *, grub_completion_type_t, int))
9723a8
 {
9723a8
-  int argc;
9723a8
-  char **argv;
9723a8
+  int argc = 0;
9723a8
+  char **argv = NULL;
9723a8
 
9723a8
   /* Initialize variables.  */
9723a8
   match = 0;
9723a8
@@ -517,10 +517,8 @@ grub_normal_do_completion (char *buf, int *restore,
9723a8
 
9723a8
  fail:
9723a8
   if (argc != 0)
9723a8
-    {
9723a8
-      grub_free (argv[0]);
9723a8
-      grub_free (argv);
9723a8
-    }
9723a8
+    grub_free (argv[0]);
9723a8
+  grub_free (argv);
9723a8
   grub_free (match);
9723a8
   grub_errno = GRUB_ERR_NONE;
9723a8