|
|
468bd4 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
468bd4 |
From: Darren Kenny <darren.kenny@oracle.com>
|
|
|
468bd4 |
Date: Fri, 22 Jan 2021 12:32:41 +0000
|
|
|
468bd4 |
Subject: [PATCH] kern/parser: Fix resource leak if argc == 0
|
|
|
468bd4 |
|
|
|
468bd4 |
After processing the command-line yet arriving at the point where we are
|
|
|
468bd4 |
setting argv, we are allocating memory, even if argc == 0, which makes
|
|
|
468bd4 |
no sense since we never put anything into the allocated argv.
|
|
|
468bd4 |
|
|
|
468bd4 |
The solution is to simply return that we've successfully processed the
|
|
|
468bd4 |
arguments but that argc == 0, and also ensure that argv is NULL when
|
|
|
468bd4 |
we're not allocating anything in it.
|
|
|
468bd4 |
|
|
|
468bd4 |
There are only 2 callers of this function, and both are handling a zero
|
|
|
468bd4 |
value in argc assuming nothing is allocated in argv.
|
|
|
468bd4 |
|
|
|
468bd4 |
Fixes: CID 96680
|
|
|
468bd4 |
|
|
|
468bd4 |
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
|
|
|
468bd4 |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
468bd4 |
---
|
|
|
468bd4 |
grub-core/kern/parser.c | 5 +++++
|
|
|
468bd4 |
1 file changed, 5 insertions(+)
|
|
|
468bd4 |
|
|
|
468bd4 |
diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c
|
|
|
468bd4 |
index 619db3122a0..d1cf061ad68 100644
|
|
|
468bd4 |
--- a/grub-core/kern/parser.c
|
|
|
468bd4 |
+++ b/grub-core/kern/parser.c
|
|
|
468bd4 |
@@ -146,6 +146,7 @@ grub_parser_split_cmdline (const char *cmdline,
|
|
|
468bd4 |
int i;
|
|
|
468bd4 |
|
|
|
468bd4 |
*argc = 0;
|
|
|
468bd4 |
+ *argv = NULL;
|
|
|
468bd4 |
do
|
|
|
468bd4 |
{
|
|
|
468bd4 |
if (!rd || !*rd)
|
|
|
468bd4 |
@@ -207,6 +208,10 @@ grub_parser_split_cmdline (const char *cmdline,
|
|
|
468bd4 |
(*argc)++;
|
|
|
468bd4 |
}
|
|
|
468bd4 |
|
|
|
468bd4 |
+ /* If there are no args, then we're done. */
|
|
|
468bd4 |
+ if (!*argc)
|
|
|
468bd4 |
+ return 0;
|
|
|
468bd4 |
+
|
|
|
468bd4 |
/* Reserve memory for the return values. */
|
|
|
468bd4 |
args = grub_malloc (bp - buffer);
|
|
|
468bd4 |
if (!args)
|