From patchwork Wed Nov 24 10:15: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: 72828 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 2B241B7080 for ; Wed, 24 Nov 2010 21:16:38 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A224C2817E; Wed, 24 Nov 2010 11:16:35 +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 oA35M2Kyi+xU; Wed, 24 Nov 2010 11:16:35 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9F9282816E; Wed, 24 Nov 2010 11:16:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 506222816E for ; Wed, 24 Nov 2010 11:16:32 +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 tMAp479C1Xm8 for ; Wed, 24 Nov 2010 11:16: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.9]) by theia.denx.de (Postfix) with ESMTP id 970032815D for ; Wed, 24 Nov 2010 11:16:31 +0100 (CET) Received: from corscience.de (DSL01.212.114.252.242.ip-pool.NEFkom.net [212.114.252.242]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0MH3Pq-1PHKlo3FKs-00DD5q; Wed, 24 Nov 2010 11:16:31 +0100 Received: from Lupus.CS.local (unknown [192.168.102.87]) by corscience.de (Postfix) with ESMTP id 414875209B; Wed, 24 Nov 2010 11:16:30 +0100 (CET) From: Thomas Weber To: u-boot@lists.denx.de Date: Wed, 24 Nov 2010 11:15:51 +0100 Message-Id: <1290593751-540-1-git-send-email-weber@corscience.de> X-Mailer: git-send-email 1.7.3.2 X-Provags-ID: V02:K0:En4iZ/yy11CBEtEiuUFlM+6UjYuJ9zAnv+My0ZgTF6d 7wdghl29viE8qmjKLecMgRp7yncnSXBvTcg5NUQsSd9QoPypK+ X4ctWVHK5aVD73QficiEnqFKh0qzwSmsfqvQjQzmowILo5/1Fo I3+wLb1aqRUF+yIHx/IEToMfMGgivgK3joRMEJ15RowMq0I0F+ em3BzZJAjsrs9Z7rWO80g== Cc: Thomas Weber Subject: [U-Boot] [RFC/PATCH] common/command.c: 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 on OMAP3/Devkit8000 when command "env" is called without subcommand. Toolchain is Codesourcery 2010q1. The cmd is NULL in this case because the calling function "do_env" decremented the argc without checking if there are still arguments available. caller: static int do_env (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ... /* drop initial "env" arg */ argc--; argv++; cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub)); Signed-off-by: Thomas Weber --- common/command.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/command.c b/common/command.c index 0020eac..03a713a 100644 --- a/common/command.c +++ b/common/command.c @@ -105,14 +105,15 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) cmd_tbl_t *cmdtp; cmd_tbl_t *cmdtp_temp = table; /*Init value */ const char *p; - int len; + int len = 0; int n_found = 0; /* * Some commands allow length modifiers (like "cp.b"); * compare command name only until first dot. */ - len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd); + if (cmd != NULL) + len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd); for (cmdtp = table; cmdtp != table + table_len;