diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-28 16:28:49 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-28 16:28:49 +0100 |
| commit | 595bfd57dc8179f9588e2a8d1e0efd1194e6246c (patch) | |
| tree | 3f1b89d8e23934b9539aa67f1b8d98e1fe54844b | |
| parent | 1c356825832e549570c690a170a84270022578e5 (diff) | |
Ensure one byte in the reply buffer for the terminator
| -rw-r--r-- | src/ot_http.c | 3 | ||||
| -rw-r--r-- | tests/integration/test_announce.py | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/ot_http.c b/src/ot_http.c index 20ec1a6..406fec3 100644 --- a/src/ot_http.c +++ b/src/ot_http.c | |||
| @@ -690,7 +690,8 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct | |||
| 690 | case 7: /* matched "ip" */ | 690 | case 7: /* matched "ip" */ |
| 691 | { | 691 | { |
| 692 | char *tmp_buf1 = ws->reply, *tmp_buf2 = ws->reply + 16; | 692 | char *tmp_buf1 = ws->reply, *tmp_buf2 = ws->reply + 16; |
| 693 | len = urlencoded_parse(&read_ptr, tmp_buf2, ws->outbuf + G_OUTBUF_SIZE, SCAN_SEARCHPATH_VALUE); | 693 | /* One short of the end, for the terminator below */ |
| 694 | len = urlencoded_parse(&read_ptr, tmp_buf2, ws->outbuf + G_OUTBUF_SIZE - 1, SCAN_SEARCHPATH_VALUE); | ||
| 694 | if (len <= 0) | 695 | if (len <= 0) |
| 695 | HTTPERROR_400_PARAM; | 696 | HTTPERROR_400_PARAM; |
| 696 | tmp_buf2[len] = 0; | 697 | tmp_buf2[len] = 0; |
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): | |||
| 124 | 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): |
| 125 | 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") |
| 126 | 126 | ||
| 127 | def test_an_ip_that_fills_the_reply_buffer_is_refused(self): | ||
| 128 | """The value is decoded into the reply buffer and then terminated, so | ||
| 129 | the longest one that fits has to leave room for the terminator. 8096 | ||
| 130 | bytes is what lies between where it is decoded and the buffer's end.""" | ||
| 131 | connection = self.tracker.connect() | ||
| 132 | try: | ||
| 133 | connection.sock.sendall(b"GET /a?ip=" + b"1" * 8096 + b"\n\n") | ||
| 134 | status, _, _ = connection.reply() | ||
| 135 | self.assertTrue(status.startswith(b"HTTP/1.0 400"), status) | ||
| 136 | finally: | ||
| 137 | connection.close() | ||
| 138 | |||
| 127 | def test_two_info_hashes_are_rejected(self): | 139 | def test_two_info_hashes_are_rejected(self): |
| 128 | self.assert_rejected("info_hash=" + "a" * 20 + "&info_hash=" + "c" * 20 + "&peer_id=" + "b" * 20 + "&port=6881&left=0") | 140 | self.assert_rejected("info_hash=" + "a" * 20 + "&info_hash=" + "c" * 20 + "&peer_id=" + "b" * 20 + "&port=6881&left=0") |
| 129 | 141 | ||
