diff mbox

[U-Boot,1/3] dm: Prevent "demo hello" and "demo status" segfaults

Message ID 1422991129-1794-1-git-send-email-ptyser@xes-inc.com
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Peter Tyser Feb. 3, 2015, 7:18 p.m. UTC
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>
---
 common/cmd_demo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Peter Tyser Feb. 3, 2015, 7:23 p.m. UTC | #1
Hi Simon,

On Tue, 2015-02-03 at 13:18 -0600, Peter Tyser wrote:
> 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>

The "1/3" in the subject line is an error - there are no other
patches in the series.

Peter
Simon Glass Feb. 3, 2015, 7:23 p.m. UTC | #2
On 3 February 2015 at 12:18, Peter Tyser <ptyser@xes-inc.com> wrote:
> 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>
> ---
>  common/cmd_demo.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Thanks!

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass Feb. 6, 2015, 9:46 p.m. UTC | #3
On 3 February 2015 at 12:23, Peter Tyser <ptyser@xes-inc.com> wrote:
> Hi Simon,
>
> On Tue, 2015-02-03 at 13:18 -0600, Peter Tyser wrote:
>> 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>
>
> The "1/3" in the subject line is an error - there are no other
> patches in the series.
>
> Peter

Applied to u-boot-dm, thanks!
diff mbox

Patch

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