Common/command: Guard strchr/strlen from NULL pointer
authorThomas Weber <weber@corscience.de>
Wed, 24 Nov 2010 12:07:51 +0000 (13:07 +0100)
committerWolfgang Denk <wd@denx.de>
Sat, 27 Nov 2010 22:35:13 +0000 (23:35 +0100)
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>
common/command.c

index 0020eac..0b1a3fb 100644 (file)
@@ -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.