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>
This commit is contained in:
Peter Tyser 2015-02-03 13:18:49 -06:00 committed by Simon Glass
parent 9009798df2
commit b922a5f94d

View File

@ -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) {