瀏覽代碼

Common/command: Guard strchr/strlen from NULL pointer

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>
Thomas Weber 14 年之前
父節點
當前提交
7013c06124
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      common/command.c

+ 2 - 0
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.