From patchwork Wed Nov 24 12:07:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Weber X-Patchwork-Id: 72847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id F3390B708B for ; Wed, 24 Nov 2010 23:13:38 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2C30E2812B; Wed, 24 Nov 2010 13:13:37 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XOTfr4DjMPur; Wed, 24 Nov 2010 13:13:36 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9C3AC2812C; Wed, 24 Nov 2010 13:13:35 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0E9892812C for ; Wed, 24 Nov 2010 13:13:33 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xtBNOy4ogm+B for ; Wed, 24 Nov 2010 13:13:31 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.8]) by theia.denx.de (Postfix) with ESMTP id 059EF2812B for ; Wed, 24 Nov 2010 13:13:29 +0100 (CET) Received: from corscience.de (DSL01.212.114.252.242.ip-pool.NEFkom.net [212.114.252.242]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0Lr6Rz-1OqrXO2gnT-00eabM; Wed, 24 Nov 2010 13:08:25 +0100 Received: from Lupus.CS.local (unknown [192.168.102.87]) by corscience.de (Postfix) with ESMTP id 0237F5209B; Wed, 24 Nov 2010 13:08:25 +0100 (CET) From: Thomas Weber To: u-boot@lists.denx.de Date: Wed, 24 Nov 2010 13:07:51 +0100 Message-Id: <1290600472-23147-1-git-send-email-weber@corscience.de> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <20101124110719.C428C135EA0@gemini.denx.de> References: <20101124110719.C428C135EA0@gemini.denx.de> X-Provags-ID: V02:K0:h28QQTBn6xFJiXzEKC1YePpaksvcEFmqCHM3bawnn7I S26PK7GDk8BqHBYC9NPsXTB43lkGO8bkzX6+yzUuy9prlZEtLF 2FEIbyasvYFlV1In3YvX6OpkzoV57yPy5W7S/ZmfW2L4Fe7fxu hamcrgDaawv6fOr5R/XMQjWPDuKDW7YrMNnnaWB7uGFI9vMk5v jBUS7OyLFOvY0H2wc7bsg== Cc: Thomas Weber Subject: [U-Boot] [RFC/PATCHv2 1/2] Common/command: Guard strchr/strlen from NULL pointer X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- Changes for v2: - Use shorter way to leave function in error case. common/command.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) 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.