mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 15:00:12 +00:00
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 <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Andrew Deason <adeason@sinenomine.net>
This commit is contained in:
parent
cbc16cec1a
commit
4f8a5b1a22
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user