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
This commit is contained in:
Daniel Stenberg 2023-06-17 23:59:14 +02:00
parent fd306e55a0
commit d40e5cc9a3
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View 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 */