Skip to content

Commit

Permalink
http: rectify the outgoing Cookie: header field size check
Browse files Browse the repository at this point in the history
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 curl#11331
  • Loading branch information
bagder authored and bch committed Jul 19, 2023
1 parent 5c7a042 commit a33e705
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/http.c
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down

0 comments on commit a33e705

Please sign in to comment.