From: Thomas Weber <weber@corscience.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC/PATCH] common/command.c: Guard strchr/strlen from NULL pointer
Date: Wed, 24 Nov 2010 11:15:51 +0100 [thread overview]
Message-ID: <1290593751-540-1-git-send-email-weber@corscience.de> (raw)
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 <weber@corscience.de>
---
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;
--
1.7.3.2
next reply other threads:[~2010-11-24 10:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-24 10:15 Thomas Weber [this message]
2010-11-24 11:07 ` [U-Boot] [RFC/PATCH] common/command.c: Guard strchr/strlen from NULL pointer Wolfgang Denk
2010-11-24 12:07 ` [U-Boot] [RFC/PATCHv2 1/2] Common/command: " Thomas Weber
2010-11-27 22:19 ` Wolfgang Denk
2010-11-24 12:07 ` [U-Boot] [RFC/PATCHv2 2/2] Common/cmd_nvedit: Check for env subcommand Thomas Weber
2010-11-27 22:19 ` Wolfgang Denk
2010-11-24 12:44 ` [U-Boot] [RFC/PATCH] common/command.c: Guard strchr/strlen from NULL pointer Sergei Shtylyov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1290593751-540-1-git-send-email-weber@corscience.de \
--to=weber@corscience.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox