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