summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Stach <l.stach@pengutronix.de>2014-08-12 18:05:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-09-01 14:24:51 +0200
commit75359aaafc0283d81e8b4be1da1179f50a09d3a4 (patch)
treee34746d551af4e377b60e7781633a6f86607bbb5
parent9b707a1fa3aad5fa03cf5bb691f059b0b8993253 (diff)
downloadbarebox-75359aaafc0283d81e8b4be1da1179f50a09d3a4.tar.gz
barebox-75359aaafc0283d81e8b4be1da1179f50a09d3a4.tar.xz
scripts: imx-image: add input validation to mw
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--scripts/imx/imx-image.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index f4890c44d7..3a25c09298 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;