]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Consume the HTTP headers after processing a request
authorMark Andrews <marka@isc.org>
Tue, 26 Oct 2021 00:54:31 +0000 (11:54 +1100)
committerEvan Hunt <each@isc.org>
Fri, 5 Nov 2021 00:00:18 +0000 (17:00 -0700)
Remember the amount of space consumed by the HTTP headers, then
move any trailing data to the start of the httpd->recvbuf once
we have finished processing the request.

lib/isc/httpd.c

index c9f78ef33196a6d64993c32e1cbce05d51459431..9596b8e0af64ce049d824ec7f568a77706f90c2f 100644 (file)
@@ -87,6 +87,7 @@ struct isc_httpd {
         */
        char recvbuf[HTTP_RECVLEN]; /*%< receive buffer */
        uint32_t recvlen;           /*%< length recv'd */
+       uint32_t consume;           /*%< length of last command */
        char *headers;              /*%< set in process_request() */
        method_t method;
        char *url;
@@ -417,9 +418,12 @@ process_request(isc_httpd_t *httpd, isc_region_t *region, size_t *buflen) {
        if (s == NULL) {
                s = strstr(httpd->recvbuf, "\n\n");
                delim = 1;
-       }
-       if (s == NULL) {
-               return (ISC_R_NOTFOUND);
+               if (s == NULL) {
+                       return (ISC_R_NOTFOUND);
+               }
+               httpd->consume = s + 2 - httpd->recvbuf;
+       } else {
+               httpd->consume = s + 4 - httpd->recvbuf;
        }
 
        /*
@@ -580,7 +584,6 @@ process_request(isc_httpd_t *httpd, isc_region_t *region, size_t *buflen) {
         * to the buffer.
         */
        *urlend = 0;
-       httpd->recvlen = 0;
 
        return (ISC_R_SUCCESS);
 }
@@ -602,6 +605,7 @@ httpd_reset(void *arg) {
 
        httpd->recvbuf[0] = 0;
        httpd->recvlen = 0;
+       httpd->consume = 0;
        httpd->headers = NULL;
        httpd->method = METHOD_UNKNOWN;
        httpd->url = NULL;
@@ -952,6 +956,17 @@ httpd_request(isc_nmhandle_t *handle, isc_result_t eresult,
        result = isc_buffer_copyregion(httpd->sendbuffer, &r);
        RUNTIME_CHECK(result == ISC_R_SUCCESS);
 
+       /* Consume the request from the recv buffer. */
+       if (httpd->consume != 0U) {
+               INSIST(httpd->consume <= httpd->recvlen);
+               if (httpd->consume < httpd->recvlen) {
+                       memmove(httpd->recvbuf, httpd->recvbuf + httpd->consume,
+                               httpd->recvlen - httpd->consume);
+               }
+               httpd->recvlen -= httpd->consume;
+               httpd->consume = 0;
+       }
+
        /*
         * Determine total response size.
         */