From 4f8a5b1a2295ba37eb4cb0eda2c459f07ac4f09a Mon Sep 17 00:00:00 2001 From: Marcio Barbosa Date: Wed, 31 Jul 2024 08:26:59 +0000 Subject: [PATCH] volinfo: Refuse zero and non-numeric -volumeid Currently, volinfo/volscan offers an optional -volumeid parameter, allowing users to specify the id of a single volume to generate output for. If this option is omitted, volinfo/volscan processes every volume in the specified partition, or all local partitions if no partition is specified. Internally, when the -volumeid parameter is not provided, its corresponding variable defaults to 0, which volinfo/volscan interprets as an indication to process all volumes. Unfortunately, if an invalid volume id is specified (e.g., a volume name instead of a number), volinfo/volscan incorrectly treats it as 0 and processes all volumes instead of validating the input and notifying the user. This issue occurs because strtoul(), the function used to convert the volume id string to a number, returns 0 when it fails to perform a valid conversion, leading volinfo/volscan to misinterpret invalid volume ids as 0. This commit fixes this issue by adding validation for the -volumeid option. It parses the result from strtoul() and returns an error if the volume id is invalid. This ensures that users are properly informed when an invalid id is provided, preventing unintended processing of all volumes in the given partition. Change-Id: I166211c8814c13f4a79273efa6408a447f0855a9 Reviewed-on: https://gerrit.openafs.org/15771 Tested-by: BuildBot Reviewed-by: Michael Meffie Reviewed-by: Andrew Deason --- src/vol/volinfo-main.c | 5 +++++ src/vol/volscan-main.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/vol/volinfo-main.c b/src/vol/volinfo-main.c index d630788eec..4b2ae986f1 100644 --- a/src/vol/volinfo-main.c +++ b/src/vol/volinfo-main.c @@ -90,6 +90,11 @@ VolInfo(struct cmd_syndesc *as, void *arock) } if ((ti = as->parms[P_VOLUMEID].items)) { volumeId = strtoul(ti->data, NULL, 10); + if (volumeId == 0) { + fprintf(stderr, "%s: Invalid -volumeid value: %s\n", progname, + ti->data); + return 1; + } } if (as->parms[P_HEADER].items) { opt->dumpHeader = 1; diff --git a/src/vol/volscan-main.c b/src/vol/volscan-main.c index 79490df445..85ab03ddc2 100644 --- a/src/vol/volscan-main.c +++ b/src/vol/volscan-main.c @@ -104,6 +104,11 @@ VolScan(struct cmd_syndesc *as, void *arock) } if ((ti = as->parms[P_VOLUMEID].items)) { volumeId = strtoul(ti->data, NULL, 10); + if (volumeId == 0) { + fprintf(stderr, "%s: Invalid -volumeid value: %s\n", progname, + ti->data); + return 1; + } } if (as->parms[P_NOHEADING].items) { opt->printHeading = 0;