From 75549625f0ba6aa56ffa4e84eedb53b5320f449f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 29 Jul 2026 13:17:30 +0200 Subject: [PATCH] fix over-writing of version string with network data read after parsing header --- src/microhttpd/connection.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 190ea72a..ce9001bf 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c @@ -6723,6 +6723,16 @@ get_req_headers (struct MHD_Connection *c, bool process_footers) { last_elmnt_end = c->rq.version + HTTP_VER_LEN; } + /* The request line strings (method, url, version) remain visible to + the application for the whole request, and the last received header + is not necessarily above them: when it is not, reclaiming down to + the header end puts the read buffer on top of the version string, + and the next recv() overwrites the terminator the application is + about to read through. Never reclaim below the end of the request + line. */ + if ((NULL != c->rq.version) && + (last_elmnt_end < c->rq.version + HTTP_VER_LEN)) + last_elmnt_end = c->rq.version + HTTP_VER_LEN; /* Check that @a last_elmnt_end points into the request that has just been parsed, which lives entirely between the start of the request line and the current read buffer