From 1c356825832e549570c690a170a84270022578e5 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 28 Nov 2026 16:27:46 +0100 Subject: Parser now rejects negative port numbers --- src/ot_http.c | 2 +- tests/integration/test_announce.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ot_http.c b/src/ot_http.c index 70176c3..20ec1a6 100644 --- a/src/ot_http.c +++ b/src/ot_http.c @@ -634,7 +634,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct break; case 1: /* matched "port" */ len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE); - if ((len <= 0) || scan_int(write_ptr, len, &tmp) || (tmp > 0xffff)) + if ((len <= 0) || scan_int(write_ptr, len, &tmp) || (tmp < 0) || (tmp > 0xffff)) HTTPERROR_400_PARAM; port = htons((uint16_t)tmp); OT_SETPORT(&ws->peer, &port); diff --git a/tests/integration/test_announce.py b/tests/integration/test_announce.py index ffbc07b..0eee0fe 100644 --- a/tests/integration/test_announce.py +++ b/tests/integration/test_announce.py @@ -118,6 +118,9 @@ class AnnounceRejects(TrackerTestCase): def test_a_port_out_of_range_is_rejected(self): self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=65536&left=0") + def test_a_negative_port_is_rejected(self): + self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=-1&left=0") + def test_a_port_that_is_not_a_number_is_rejected(self): self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=abc&left=0") -- cgit v1.3