summaryrefslogtreecommitdiff
path: root/cgpt
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2019-08-28 18:38:31 -0400
committerCommit Bot <commit-bot@chromium.org>2019-08-29 02:11:38 +0000
commit31bda282648dd662b1f9c7c8cb8c2dfc8ca27585 (patch)
tree8ef78f65193ae38d747af21d7dc97c7b4e0c233d /cgpt
parentafd52397565311166a97f7681209c2f9d3a2d37a (diff)
downloadvboot-31bda282648dd662b1f9c7c8cb8c2dfc8ca27585.tar.gz
cgpt: show: add some sanity checking to -i flagsstabilize-12464.B
If people use -i0, the code runs as if the flag wasn't specified. Since valid partition numbers are [1,128], and the lower layers already reject values outside that range (except for 0), add an explicit check to the CLI for -i0. Trying to display specific fields w/out -i makes no sense, and the lower layers just ignore it. Add an explicit check for it so users don't try to do `cgpt show /dev/sda -s` and wonder why the output is unchanged. Passing more than one specific field selector like -s -b doesn't work -- whatever flag was specified last wins. This isn't that obvious to users, so throw an explicit error when it happens. BUG=None TEST=CQ passes BRANCH=None Change-Id: I7c98822b79b389824b544b128ede93458b678342 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1773964 Reviewed-by: Julius Werner <jwerner@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r--cgpt/cmd_show.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/cgpt/cmd_show.c b/cgpt/cmd_show.c
index 22d31841..4d169f5e 100644
--- a/cgpt/cmd_show.c
+++ b/cgpt/cmd_show.c
@@ -70,6 +70,10 @@ int cmd_show(int argc, char *argv[]) {
case 'i':
params.partition = (uint32_t)strtoul(optarg, &e, 0);
errorcnt += check_int_parse(c, e);
+ if (params.partition <= 0) {
+ Error("-i requires a number between 1 and 128 (inclusive)\n");
+ errorcnt++;
+ }
break;
case 'b':
case 's':
@@ -82,6 +86,12 @@ int cmd_show(int argc, char *argv[]) {
case 'R':
case 'B':
case 'A':
+ if (params.single_item) {
+ Error("-%c already specified; rejecting additional -%c\n",
+ params.single_item, c);
+ Error("Only a single item may be displayed at a time\n");
+ errorcnt++;
+ }
params.single_item = c;
break;
@@ -105,6 +115,10 @@ int cmd_show(int argc, char *argv[]) {
break;
}
}
+ if (!params.partition && params.single_item) {
+ Error("-i required when displaying a single item\n");
+ errorcnt++;
+ }
if (errorcnt)
{
Usage();