Blame SOURCES/0390-kern-parser-Fix-resource-leak-if-argc-0.patch

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