diff mbox

[U-Boot,RFC/PATCHv2,1/2] Common/command: Guard strchr/strlen from NULL pointer

Message ID 1290600472-23147-1-git-send-email-weber@corscience.de
State Accepted
Commit 7013c06124e9760f75ef194d429ed29fba843eb9
Headers show

Commit Message

Thomas Weber Nov. 24, 2010, 12:07 p.m. UTC
Guard strchr/strlen from being called with NULL pointer.
This line is crashing when command "env" is called without subcommand.

The cmd is NULL in this case because the calling function "do_env"
decremented the argc without checking if there are still arguments available.

Signed-off-by: Thomas Weber <weber@corscience.de>
---
Changes for v2: 
	- Use shorter way to leave function in error case.

 common/command.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Wolfgang Denk Nov. 27, 2010, 10:19 p.m. UTC | #1
Dear Thomas Weber,

In message <1290600472-23147-1-git-send-email-weber@corscience.de> you wrote:
> Guard strchr/strlen from being called with NULL pointer.
> This line is crashing when command "env" is called without subcommand.
> 
> The cmd is NULL in this case because the calling function "do_env"
> decremented the argc without checking if there are still arguments available.
> 
> Signed-off-by: Thomas Weber <weber@corscience.de>
> ---
> Changes for v2: 
> 	- Use shorter way to leave function in error case.
> 
>  common/command.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/common/command.c b/common/command.c
index 0020eac..0b1a3fb 100644
--- a/common/command.c
+++ b/common/command.c
@@ -108,6 +108,8 @@  cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
 	int len;
 	int n_found = 0;
 
+	if (!cmd)
+		return NULL;
 	/*
 	 * Some commands allow length modifiers (like "cp.b");
 	 * compare command name only until first dot.