From: Lucas Stach <l.stach@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/4] scripts: imx-image: add input validation to mw
Date: Tue, 12 Aug 2014 18:05:50 +0200 [thread overview]
Message-ID: <1407859552-20180-2-git-send-email-l.stach@pengutronix.de> (raw)
In-Reply-To: <1407859552-20180-1-git-send-email-l.stach@pengutronix.de>
Stop and print a helpful message if we encounter an
illegal token while parsing the DCD config, instead
of silently swallowing the error and pushing random
stuff into the DCD.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
scripts/imx/imx-image.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index f4890c44d7fa..3a25c0929883 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -384,15 +384,30 @@ static int do_cmd_check(int argc, char *argv[])
static int do_cmd_write_mem(int argc, char *argv[])
{
uint32_t addr, val, width;
+ char *end;
if (argc != 4) {
fprintf(stderr, "usage: wm [8|16|32] <addr> <val>\n");
return -EINVAL;
}
- width = strtoul(argv[1], NULL, 0);
- addr = strtoul(argv[2], NULL, 0);
- val = strtoul(argv[3], NULL, 0);
+ width = strtoul(argv[1], &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "illegal width token \"%s\"\n", argv[1]);
+ return -EINVAL;
+ }
+
+ addr = strtoul(argv[2], &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "illegal address token \"%s\"\n", argv[2]);
+ return -EINVAL;
+ }
+
+ val = strtoul(argv[3], &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "illegal value token \"%s\"\n", argv[3]);
+ return -EINVAL;
+ }
width >>= 3;
--
2.0.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-08-12 16:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-12 16:05 [PATCH 1/4] Makefile.lib: imxcfg: fix include path Lucas Stach
2014-08-12 16:05 ` Lucas Stach [this message]
2014-08-12 16:05 ` [PATCH 3/4] arm: mach-imx: add MMDC and CCM register defines for use in DCD Lucas Stach
2014-08-12 16:05 ` [PATCH 4/4] arm: nitrogen6x: new memory setup from BD u-boot Lucas Stach
2014-09-01 9:17 ` [PATCH 1/4] Makefile.lib: imxcfg: fix include path Sascha Hauer
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=1407859552-20180-2-git-send-email-l.stach@pengutronix.de \
--to=l.stach@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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