Repository navigation
fix(cli): reject malformed resolver ports and an explicit -attempts 0 - #339
Merged
Merged
Conversation
ParseResolverList accepted any port SplitHostPort returned, so -r entries such as 9.9.9.9:abc, 9.9.9.9:99999 or 9.9.9.9:0 parsed fine and then failed every lookup at dial time; a list of only those died in the reliability guard instead of at input. Validate the port with the same 1-65535 rule -dns-server uses (now exported as validate.Port) and name the offending line. effectiveAttempts decided "given" from the value, so an explicit -attempts 0 (flag, env or config) was read as unset and ran with one attempt silently, while -attempts -1 was rejected. Decide from the source instead, so 0 reaches Options.Validate like any other out-of-range value and -attempts 0 -retries 3 reports the cannot-use-both error.
TMHSDigital
added a commit
that referenced
this pull request
Nov 15, 2026
PR #339 rejected malformed -r ports and an explicit -attempts 0 but added no changelog entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Two input-validation gaps from #318, both rejected on one side of the boundary and accepted on the other:
-rfile entry with a non-numeric or out-of-range port (9.9.9.9:abc,9.9.9.9:99999,9.9.9.9:0,9.9.9.9:-1) is accepted, then fails every lookup at dial time. A list with no good member dies inside the reliability guard ("likely resolver rate-limiting") instead of at input.-attempts 0(flag,SUBENUM_ATTEMPTS=0or config) runs with one attempt and no message, while-attempts -1is rejected byOptions.Validate. Fixes Resolver list accepts invalid ports; -attempts 0 is silently treated as 1 #318.Root cause
ParseResolverList(internal/dns/pool.go) checked host and port for emptiness but never the port range — unlike the-dns-serverpath, which goes throughvalidate.DNSServer's 1-65535 check.effectiveAttempts(internal/cli/cli.go) used the flag value as the "given" marker:attemptsSet := attempts != 0. Since 0 is the flag default, an explicit 0 was indistinguishable from "not passed" and short-circuited to the default of 1 before any validation ran.Fix
validate.checkPortis exported asvalidate.Port;internal/dnsalready imported the package, soParseResolverListnow applies the same 1-65535 rule and wraps the error with the offending line:invalid resolver "9.9.9.9:99999": invalid port: 99999 (must be 1-65535).effectiveAttemptsdecides "given" from the source (attemptsSrc != sourceDefault), for-retriestoo. An explicit 0 now flows through toOptions.Validate, which already rejects< 1;-attempts 0 -retries 3now reports the "cannot use both" error instead of silently using 3.Testing
internal/dns/pool_test.go:TestParseResolverListRejectsBadPorts— table overabc,99999,0,-1, asserting an error that names the line and states the range.internal/cli/cli_test.go:TestEffectiveAttemptsextended — explicit-attempts 0(flag and config source) returns 0 so validation rejects it, and-attempts 0 -retries 3returns the cannot-use-both error.Negative control: with the three source files reverted,
TestParseResolverListRejectsBadPortsandTestEffectiveAttemptsfail (4 assertions), so the tests cover the change.