From: Peter Tyser <ptyser@xes-inc.com>
Date: Tue, 3 Feb 2015 19:18:49 +0000 (-0600)
Subject: dm: Prevent "demo hello" and "demo status" segfaults
X-Git-Tag: v2025.01-rc5-pxa1908~13792^2~50
X-Git-Url: http://git.dujemihanovic.xyz/%22/icons/right.gif/static/git-favicon.png?a=commitdiff_plain;h=b922a5f94d960b0464f81b439c34707071095565;p=u-boot.git

dm: Prevent "demo hello" and "demo status" segfaults

Segfaults can occur when a mandatory argument is not provided to
"demo hello" and "demo status".  Eg:

   => demo hello
   Segmentation fault (core dumped)

Add a check to ensure all required arguments are provided.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Acked-by: Simon Glass <sjg@chromium.org>
---

diff --git a/common/cmd_demo.c b/common/cmd_demo.c
index bcb34d9045..8a10bdf42a 100644
--- a/common/cmd_demo.c
+++ b/common/cmd_demo.c
@@ -97,7 +97,9 @@ static int do_demo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				ARRAY_SIZE(demo_commands));
 	argc -= 2;
 	argv += 2;
-	if (!demo_cmd || argc > demo_cmd->maxargs)
+
+	if ((!demo_cmd || argc > demo_cmd->maxargs) ||
+	    ((demo_cmd->name[0] != 'l') && (argc < 1)))
 		return CMD_RET_USAGE;
 
 	if (argc) {