From 595bfd57dc8179f9588e2a8d1e0efd1194e6246c Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 28 Nov 2026 16:28:49 +0100 Subject: Ensure one byte in the reply buffer for the terminator --- tests/integration/test_announce.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/integration/test_announce.py b/tests/integration/test_announce.py index 0eee0fe..2d21417 100644 --- a/tests/integration/test_announce.py +++ b/tests/integration/test_announce.py @@ -124,6 +124,18 @@ class AnnounceRejects(TrackerTestCase): 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") + def test_an_ip_that_fills_the_reply_buffer_is_refused(self): + """The value is decoded into the reply buffer and then terminated, so + the longest one that fits has to leave room for the terminator. 8096 + bytes is what lies between where it is decoded and the buffer's end.""" + connection = self.tracker.connect() + try: + connection.sock.sendall(b"GET /a?ip=" + b"1" * 8096 + b"\n\n") + status, _, _ = connection.reply() + self.assertTrue(status.startswith(b"HTTP/1.0 400"), status) + finally: + connection.close() + def test_two_info_hashes_are_rejected(self): self.assert_rejected("info_hash=" + "a" * 20 + "&info_hash=" + "c" * 20 + "&peer_id=" + "b" * 20 + "&port=6881&left=0") -- cgit v1.3