nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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