]> git.sur5r.net Git - u-boot/commitdiff
dm: Prevent "demo hello" and "demo status" segfaults
authorPeter Tyser <ptyser@xes-inc.com>
Tue, 3 Feb 2015 19:18:49 +0000 (13:18 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 12 Feb 2015 17:35:29 +0000 (10:35 -0700)
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>
common/cmd_demo.c

index bcb34d904569d98612317dcc4e0712db6edd6410..8a10bdf42a8906b9f212fe82c3d42afc79d5c028 100644 (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) {