From: Daniel Stenberg Date: Sat, 17 Jun 2023 21:59:14 +0000 (+0200) Subject: http: rectify the outgoing Cookie: header field size check X-Git-Tag: curl-8_2_0~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d40e5cc9a3c7c5ba88523be0272f842ca8672357;p=thirdparty%2Fcurl.git http: rectify the outgoing Cookie: header field size check 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 --- diff --git a/lib/http.c b/lib/http.c index 219dcc2c00..bc09f26312 100644 --- a/lib/http.c +++ b/lib/http.c @@ -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 */