1From d06161b035dde4769199ad65aa0a587a5920012b Mon Sep 17 00:00:00 2001 2From: Darren Kenny <darren.kenny@oracle.com> 3Date: Fri, 22 Jan 2021 12:32:41 +0000 4Subject: [PATCH] kern/parser: Fix resource leak if argc == 0 5 6After processing the command-line yet arriving at the point where we are 7setting argv, we are allocating memory, even if argc == 0, which makes 8no sense since we never put anything into the allocated argv. 9 10The solution is to simply return that we've successfully processed the 11arguments but that argc == 0, and also ensure that argv is NULL when 12we're not allocating anything in it. 13 14There are only 2 callers of this function, and both are handling a zero 15value in argc assuming nothing is allocated in argv. 16 17Fixes: CID 96680 18 19Signed-off-by: Darren Kenny <darren.kenny@oracle.com> 20Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 21Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 22--- 23 grub-core/kern/parser.c | 5 +++++ 24 1 file changed, 5 insertions(+) 25 26diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c 27index 619db31..d1cf061 100644 28--- a/grub-core/kern/parser.c 29+++ b/grub-core/kern/parser.c 30@@ -146,6 +146,7 @@ grub_parser_split_cmdline (const char *cmdline, 31 int i; 32 33 *argc = 0; 34+ *argv = NULL; 35 do 36 { 37 if (!rd || !*rd) 38@@ -207,6 +208,10 @@ grub_parser_split_cmdline (const char *cmdline, 39 (*argc)++; 40 } 41 42+ /* If there are no args, then we're done. */ 43+ if (!*argc) 44+ return 0; 45+ 46 /* Reserve memory for the return values. */ 47 args = grub_malloc (bp - buffer); 48 if (!args) 49-- 502.14.2 51 52