fix: reject a nonpositive -sample instead of widening the scan - #12
Merged
Merged
Conversation
A nonpositive value reached expandPools as the same sentinel -full uses, so -sample -1 scanned every address in every subnet instead of failing. The bound now sits on the flag itself, so the value cannot enter options at all. Fixes vernette#8
Owner
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8.
expandV4treats a sample of<= 0as "the whole subnet" the sentinel-fullsets, soscan -n -1quietly scanned all 256 addresses of every pool instead of failing.What changed
-sampleis now bounded at 1 by the flag's own parser (flag.Func), so a nonpositive value is a usage error: exit status 2 andinvalid value "-1" for flag -n: must be at least 1, the way-n abcalready failed.This covers both commands that register the flag and every spelling of it.
-fulland the sentinel behind it are untouched, and-sample 300still scans all 256 addresses:expandV4clamps, and asking for 300 of 256 can only mean all of them.intFlagValidateis not specific to-sample; any int flag with a bound can move onto it.One behaviour difference
The bound applies per occurrence rather than to the final value:
-n 5 -n 0is now rejected, which is the point, and-n 0 -n 5is rejected too, which is new.No test
None of the flag validations in the tree are tested, and a test here would mostly assert that
flagcallsSet. Verified by hand on both commands, including the-target 1.2.3.0/29repro from the issue.