[U-Boot] [PATCH 1/3] dm: Prevent "demo hello" and "demo status" segfaults
Peter Tyser
ptyser at xes-inc.com
Tue Feb 3 20:18:49 CET 2015
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 at xes-inc.com>
---
common/cmd_demo.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/common/cmd_demo.c b/common/cmd_demo.c
index 652c61c..b8b8578 100644
--- a/common/cmd_demo.c
+++ b/common/cmd_demo.c
@@ -76,7 +76,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) {
--
1.9.1
More information about the U-Boot
mailing list