Patchwork [U-Boot,06/10] dfu: Fix crash when wrong number of arguments given

login
register
mail settings
Submitter Pantelis Antoniou
Date Nov. 29, 2012, 7:33 a.m.
Message ID <1354174439-5589-7-git-send-email-panto@antoniou-consulting.com>
Download mbox | patch
Permalink /patch/202412/
State Superseded
Delegated to: Marek Vasut
Headers show

Comments

Ɓukasz Majewski - Nov. 28, 2012, 3:17 p.m.
Hi Pantelis,

> Fix obvious crash when not enough arguments are given to the dfu
> command.
> 
> Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
> ---
>  common/cmd_dfu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
> index 327c738..83ef324 100644
> --- a/common/cmd_dfu.c
> +++ b/common/cmd_dfu.c
> @@ -50,7 +50,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int
> argc, char * const argv[]) if (ret)
>  		return CMD_RET_FAILURE;
>  
> -	if (strcmp(argv[3], "list") == 0) {
> +	if (argc > 3 && strcmp(argv[3], "list") == 0) {

I'd add the (argc > 4) to the very beginning check: 
if (argc < 3 || argc > 4)
	return CMD_RET_USAGE;

and leave below code unchanged:

if (strcmp(argv[3], "list") == 0) {
	dfu_show_entities();
	goto done;
}


>  		dfu_show_entities();
>  		goto done;
>  	}
Pantelis Antoniou - Nov. 29, 2012, 7:33 a.m.
Fix obvious crash when not enough arguments are given to the dfu
command.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
---
 common/cmd_dfu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch

diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
index 327c738..83ef324 100644
--- a/common/cmd_dfu.c
+++ b/common/cmd_dfu.c
@@ -50,7 +50,7 @@  static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (ret)
 		return CMD_RET_FAILURE;
 
-	if (strcmp(argv[3], "list") == 0) {
+	if (argc > 3 && strcmp(argv[3], "list") == 0) {
 		dfu_show_entities();
 		goto done;
 	}