Repository navigation
fix: reject empty ports in tcp4 address validation - #1659
sergioperezcheco wants to merge 1 commit into
Conversation
Preserve explicit port zero and the existing address resolution checks. Co-Authored-By: OpenAI GPT-6.1-Sol <noreply@openai.com> Signed-off-by: sergioperezcheco <checo520@outlook.com>
|
According to the documentation, Lines 1302 to 1306 in f3194ca What is the TCP (or TCP4) address? This is what the "address" refers to. Address does not include port. Am I wrong? |
|
Good question — and the docs are indeed easy to read that way. Empirically, though, The gap it closes is the empty-port form: |
Reject an empty TCP4 port
tcp4_addraccepts127.0.0.1:becausenet.ResolveTCPAddrtreats an empty port as zero. Check the host/port split before resolution and reject an empty port, as discussed in #1003. Explicit:0remains valid, and the existing IPv4 and port-range checks are preserved.The regression exercises both
Validate.VarandValidate.Structfor empty, missing, zero, normal, maximum, overflowing and negative ports, plus an invalid IPv4 address. The original implementation fails the two empty-port cases; the change passes all nine cases. Native Go 1.26.4 validation passedgo test -race -cover ./...,go vet ./..., and golangci-lint v2.13.1 with zero issues. Other OS/Go-version matrix jobs have not been run locally.Fixes #1003.
AI-assisted contribution: investigation, implementation, tests and this description were produced with OpenAI GPT-6.1-Sol through Hermes; the commit includes the required model attribution.