diff options
author | Cyril Bur <cyril.bur@au1.ibm.com> | 2017-07-28 16:46:26 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2017-08-01 13:57:27 +1000 |
commit | 36bab769e72d0fe354ab5225194839bfca7326b8 (patch) | |
tree | 7d2bd0f19892d5b5cf85655d2691a4eba61f52c8 | |
parent | c0aa2f9decd968730ed6e2ac976f03aeac048552 (diff) | |
download | skiboot-36bab769e72d0fe354ab5225194839bfca7326b8.zip skiboot-36bab769e72d0fe354ab5225194839bfca7326b8.tar.gz skiboot-36bab769e72d0fe354ab5225194839bfca7326b8.tar.bz2 |
external/pflash: Check the result of strtoul
Also add 0x in front of --info output to avoid a copy and paste mistake.
Reported-by: Michael Neuling <mikey@neuling.org>
Suggested-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | external/pflash/pflash.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 26bccff..afaba8e 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -132,7 +132,7 @@ static void print_ffs_info(uint32_t toc_offset) goto out; end = start + size; - printf("ID=%02d %15s %08x..%08x (actual=%08x) %s\n", + printf("ID=%02d %15s 0x%08x..0x%08x (actual=0x%08x) %s\n", i, name, start, end, act, flags); if (strcmp(name, "OTHER_SIDE") == 0) @@ -618,7 +618,7 @@ int main(int argc, char *argv[]) bool no_action = false, tune = false; char *write_file = NULL, *read_file = NULL, *part_name = NULL; bool ffs_toc_seen = false, direct = false, print_detail = false; - int rc; + int rc = 0; while(1) { struct option long_opts[] = { @@ -654,11 +654,21 @@ int main(int argc, char *argv[]) if (c == -1) break; switch(c) { + char *endptr; + case 'a': - address = strtoul(optarg, NULL, 0); + address = strtoul(optarg, &endptr, 0); + if (*endptr != '\0') { + rc = 1; + no_action = true; + } break; case 's': - read_size = write_size = strtoul(optarg, NULL, 0); + read_size = write_size = strtoul(optarg, &endptr, 0); + if (*endptr != '\0') { + rc = 1; + no_action = true; + } break; case 'P': part_name = strdup(optarg); @@ -719,15 +729,24 @@ int main(int argc, char *argv[]) break; case 'T': ffs_toc_seen = true; - ffs_toc = strtoul(optarg, NULL, 0); + ffs_toc = strtoul(optarg, &endptr, 0); + if (*endptr != '\0') { + rc = 1; + no_action = true; + } break; case 'c': do_clear = true; break; case 'm': print_detail = true; - if (optarg) - detail_id = strtoul(optarg, NULL, 0); + if (optarg) { + detail_id = strtoul(optarg, &endptr, 0); + if (*endptr != '\0') { + rc = 1; + no_action = true; + } + } break; case ':': fprintf(stderr, "Unrecognised option \"%s\" to '%c'\n", optarg, optopt); @@ -770,7 +789,7 @@ int main(int argc, char *argv[]) print_help(pname); if (no_action) - return 0; + return rc; /* --enable-4B and --disable-4B are mutually exclusive */ if (enable_4B && disable_4B) { |