From 4cc0cc12960bf4861aa9e299af997e4564338166 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Sun, 25 Oct 2026 06:45:45 +0000 Subject: [PATCH] fix(profile): reject rules with a reversed port range A rule such as "- * TCP/8000-80" was accepted, but its start port is greater than its end port, so it never matched any connection. Reject it during parsing so the rule settings show an error instead of silently ignoring the rule. --- service/profile/endpoints/endpoint.go | 3 +++ service/profile/endpoints/endpoint_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/service/profile/endpoints/endpoint.go b/service/profile/endpoints/endpoint.go index 2c28aac44..8aa8c5c5c 100644 --- a/service/profile/endpoints/endpoint.go +++ b/service/profile/endpoints/endpoint.go @@ -195,6 +195,9 @@ func (ep *EndpointBase) parsePPP(typedEp Endpoint, fields []string) (Endpoint, e if n16 == 0 { return nil, invalidDefinitionError(fields, "port number cannot be 0") } + if n16 < ep.StartPort { + return nil, invalidDefinitionError(fields, "start port cannot be greater than end port") + } ep.EndPort = n16 } } diff --git a/service/profile/endpoints/endpoint_test.go b/service/profile/endpoints/endpoint_test.go index 1af937e0d..839d55f07 100644 --- a/service/profile/endpoints/endpoint_test.go +++ b/service/profile/endpoints/endpoint_test.go @@ -62,6 +62,19 @@ func TestEndpointParsing(t *testing.T) { // TODO: Test fails: // testParsing(t, "+ 1234") + + // invalid protocol and ports + testParsingFails(t, "+ * TCP/443-80") + testParsingFails(t, "- * UDP/HTTPS-HTTP") +} + +func testParsingFails(t *testing.T, value string) { + t.Helper() + + ep, err := parseEndpoint(value) + if err == nil { + t.Errorf(`parsing "%s" should fail, but returned "%s"`, value, ep.String()) + } } func testParsing(t *testing.T, value string) {