Skip to content

Commit

Permalink
content_encoding: return error on too many compression steps
Browse files Browse the repository at this point in the history
The max allowed steps is arbitrarily set to 5.

Bug: https://curl.se/docs/CVE-2022-32206.html
CVE-2022-32206
Reported-by: Harry Sintonen
Closes #9049
  • Loading branch information
bagder committed Jun 25, 2022
1 parent 6ecdf51 commit 3a09fbb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/content_encoding.c
Expand Up @@ -1028,12 +1028,16 @@ static const struct content_encoding *find_encoding(const char *name,
return NULL;
}

/* allow no more than 5 "chained" compression steps */
#define MAX_ENCODE_STACK 5

/* Set-up the unencoding stack from the Content-Encoding header value.
* See RFC 7231 section 3.1.2.2. */
CURLcode Curl_build_unencoding_stack(struct Curl_easy *data,
const char *enclist, int maybechunked)
{
struct SingleRequest *k = &data->req;
int counter = 0;

do {
const char *name;
Expand Down Expand Up @@ -1068,6 +1072,11 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data,
if(!encoding)
encoding = &error_encoding; /* Defer error at stack use. */

if(++counter >= MAX_ENCODE_STACK) {
failf(data, "Reject response due to %u content encodings",
counter);
return CURLE_BAD_CONTENT_ENCODING;
}
/* Stack the unencoding stage. */
writer = new_unencoding_writer(data, encoding, k->writer_stack);
if(!writer)
Expand Down

0 comments on commit 3a09fbb

Please sign in to comment.