From: Malte S. Stretz Date: Wed, 22 Jun 2011 20:27:53 +0000 (+0200) Subject: Bail out early if the request is too large. X-Git-Tag: 3.0.715~18 X-Git-Url: https://unix4lyfe.org/gitweb/darkstat/commitdiff_plain/6d2794d6dcede44b47038e5620e29bd9bf648961?hp=f309b723be645e15b021a97431b9e9266b9e0874 Bail out early if the request is too large. There is no point parsing the request first. --- diff --git a/http.c b/http.c index 642f706..fa77183 100644 --- a/http.c +++ b/http.c @@ -727,6 +727,15 @@ static void poll_recv_request(struct connection *conn) conn->request_length += recvd; conn->request[conn->request_length] = 0; + /* die if it's too long */ + if (conn->request_length > MAX_REQUEST_LENGTH) + { + default_reply(conn, 413, "Request Entity Too Large", + "Your request was dropped because it was too long."); + conn->state = SEND_HEADER; + return; + } + /* process request if we have all of it */ if (conn->request_length > 4 && memcmp(conn->request+conn->request_length-4, "\r\n\r\n", 4) == 0) @@ -737,14 +746,6 @@ static void poll_recv_request(struct connection *conn) free(conn->request); conn->request = NULL; /* important: don't free it again later */ } - - /* die if it's too long */ - if (conn->request_length > MAX_REQUEST_LENGTH) - { - default_reply(conn, 413, "Request Entity Too Large", - "Your request was dropped because it was too long."); - conn->state = SEND_HEADER; - } }