summaryrefslogtreecommitdiff
path: root/src/ot_http.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-06 21:17:54 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-06 21:17:54 +0100
commita29e606b6f97c00d0b7e80cb0592bca54f92f2c9 (patch)
tree3907ef58492c459bd64e1381117f16083c4968cf /src/ot_http.c
parent1d7ed6b295a5a9509d8194ce2a03255f0fb5a5fc (diff)
Fix a theoretical bug where a short request packet yields an oob read
Diffstat (limited to 'src/ot_http.c')
-rw-r--r--src/ot_http.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/ot_http.c b/src/ot_http.c
index fc49333..1b5281c 100644
--- a/src/ot_http.c
+++ b/src/ot_http.c
@@ -762,8 +762,8 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) {
762 } 762 }
763 } 763 }
764 764
765 /* This one implicitely tests strlen < 5, too -- remember, it is \n terminated */ 765 /* The request need not be NUL terminated and can be shorter than the literal */
766 if (memcmp(read_ptr, "GET /", 5)) 766 if (ws->request_size < 5 || memcmp(read_ptr, "GET /", 5))
767 HTTPERROR_400; 767 HTTPERROR_400;
768 768
769 /* Skip leading '/' */ 769 /* Skip leading '/' */
@@ -786,7 +786,7 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) {
786 if ((*write_ptr == 'a') || (*write_ptr == '?')) 786 if ((*write_ptr == 'a') || (*write_ptr == '?'))
787 http_handle_announce(sock, ws, read_ptr); 787 http_handle_announce(sock, ws, read_ptr);
788#ifdef WANT_FULLSCRAPE 788#ifdef WANT_FULLSCRAPE
789 else if (!memcmp(write_ptr, "scrape HTTP/", 12)) 789 else if (ws->request + ws->request_size - write_ptr >= 12 && !memcmp(write_ptr, "scrape HTTP/", 12))
790 http_handle_fullscrape(sock, ws); 790 http_handle_fullscrape(sock, ws);
791#endif 791#endif
792 /* This is the hardcore match for scrape */ 792 /* This is the hardcore match for scrape */