Skip to content

Commit

Permalink
http: use the per-request header counter to check for too large headers
Browse files Browse the repository at this point in the history
Not the counter that accumulates all headers over all redirects.

Yes: this means that if you allow following unbounded redirects in
never-ending loops, curl can run out of memory.

Fixes #11871
Reported-by: Joshix-1 on github
  • Loading branch information
bagder committed Sep 16, 2023
1 parent adbb7a0 commit 90d7dfc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lib/http.c
Expand Up @@ -3971,17 +3971,18 @@ CURLcode Curl_bump_headersize(struct Curl_easy *data,
{
size_t bad = 0;
if(delta < MAX_HTTP_RESP_HEADER_SIZE) {
data->info.header_size += (unsigned int)delta;
data->req.allheadercount += (unsigned int)delta;
if(!connect_only)
data->req.headerbytecount += (unsigned int)delta;
data->info.header_size += (unsigned int)delta;
if(data->info.header_size > MAX_HTTP_RESP_HEADER_SIZE)
bad = data->info.header_size;
if(data->req.allheadercount > MAX_HTTP_RESP_HEADER_SIZE)
bad = data->req.allheadercount;
}
else
bad = data->info.header_size + delta;
bad = data->req.allheadercount + delta;
if(bad) {
failf(data, "Too large response headers: %zu > %u",
bad, MAX_HTTP_RESP_HEADER_SIZE);
failf(data, "Too large response headers: %zu > %u", bad,
MAX_HTTP_RESP_HEADER_SIZE);
return CURLE_RECV_ERROR;
}
return CURLE_OK;
Expand Down
4 changes: 3 additions & 1 deletion lib/urldata.h
Expand Up @@ -640,7 +640,9 @@ struct SingleRequest {
curl_off_t pendingheader; /* this many bytes left to send is actually
header and not body */
struct curltime start; /* transfer started at this time */
unsigned int headerbytecount; /* only count received headers */
unsigned int headerbytecount; /* received server headers (not CONNECT
headers) */
unsigned int allheadercount; /* all received headers (server + CONNECT) */
unsigned int deductheadercount; /* this amount of bytes doesn't count when
we check if anything has been transferred
at the end of a connection. We use this
Expand Down

0 comments on commit 90d7dfc

Please sign in to comment.