]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http: rectify the outgoing Cookie: header field size check
authorDaniel Stenberg <daniel@haxx.se>
Sat, 17 Jun 2023 21:59:14 +0000 (23:59 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 18 Jun 2023 09:07:23 +0000 (11:07 +0200)
Previously it would count the size of the entire outgoing request and
not just the size of only the Cookie: header field - which was the
intention.

This could make the check be off by several hundred bytes in some cases.

Closes #11331

lib/http.c

index 219dcc2c00f3716b8572de461997514b7e7a30c1..bc09f263129a02b6135590566237e485d03c3c20 100644 (file)
@@ -2832,16 +2832,18 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
     }
     if(co) {
       struct Cookie *store = co;
+      size_t clen = 8; /* hold the size of the generated Cookie: header */
       /* now loop through all cookies that matched */
       while(co) {
         if(co->value) {
-          if(0 == count) {
+          size_t add;
+          if(!count) {
             result = Curl_dyn_addn(r, STRCONST("Cookie: "));
             if(result)
               break;
           }
-          if((Curl_dyn_len(r) + strlen(co->name) + strlen(co->value) + 1) >=
-             MAX_COOKIE_HEADER_LEN) {
+          add = strlen(co->name) + strlen(co->value) + 1;
+          if(clen + add >= MAX_COOKIE_HEADER_LEN) {
             infof(data, "Restricted outgoing cookies due to header size, "
                   "'%s' not sent", co->name);
             linecap = TRUE;
@@ -2851,6 +2853,7 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
                                  co->name, co->value);
           if(result)
             break;
+          clen += add + (count ? 2 : 0);
           count++;
         }
         co = co->next; /* next cookie please */