summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-28 16:27:46 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-28 16:27:46 +0100
commit1c356825832e549570c690a170a84270022578e5 (patch)
tree9d404d329d61623a62832ddd89fc26742623de4f
parentbfef6800268cdcf0b9118d89f1ce7c3541bd0309 (diff)
Parser now rejects negative port numbers
-rw-r--r--src/ot_http.c2
-rw-r--r--tests/integration/test_announce.py3
2 files changed, 4 insertions, 1 deletions
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
634 break; 634 break;
635 case 1: /* matched "port" */ 635 case 1: /* matched "port" */
636 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE); 636 len = urlencoded_parse(&read_ptr, write_ptr = read_ptr, ws->request + ws->request_size, SCAN_SEARCHPATH_VALUE);
637 if ((len <= 0) || scan_int(write_ptr, len, &tmp) || (tmp > 0xffff)) 637 if ((len <= 0) || scan_int(write_ptr, len, &tmp) || (tmp < 0) || (tmp > 0xffff))
638 HTTPERROR_400_PARAM; 638 HTTPERROR_400_PARAM;
639 port = htons((uint16_t)tmp); 639 port = htons((uint16_t)tmp);
640 OT_SETPORT(&ws->peer, &port); 640 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):
118 def test_a_port_out_of_range_is_rejected(self): 118 def test_a_port_out_of_range_is_rejected(self):
119 self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=65536&left=0") 119 self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=65536&left=0")
120 120
121 def test_a_negative_port_is_rejected(self):
122 self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=-1&left=0")
123
121 def test_a_port_that_is_not_a_number_is_rejected(self): 124 def test_a_port_that_is_not_a_number_is_rejected(self):
122 self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=abc&left=0") 125 self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=abc&left=0")
123 126