curl/backport-CVE-2022-32206.patch
eaglegai fc09d7a50b fix CVE-2022-32205 CVE-2022-32206 CVE-2022-32207 CVE-2022-32208
(cherry picked from commit 396042a7112f4f568fdea60b6eeca9a89e3b7413)
2022-06-29 11:49:30 +08:00

43 lines
1.5 KiB
Diff

Backported of:
From 7035676c3daa4f1c3766095561f12e7a0e82c736 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Mon, 16 May 2022 16:28:13 +0200
Subject: [PATCH] content_encoding: return error on too many compression steps
The max allowed steps is arbitrarily set to 5.
diff --git a/lib/content_encoding.c b/lib/content_encoding.c
index 82fcc2b..a89bb3e 100644
--- a/lib/content_encoding.c
+++ b/lib/content_encoding.c
@@ -1027,6 +1027,9 @@ 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 connectdata *conn,
@@ -1034,6 +1037,7 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn,
{
struct Curl_easy *data = conn->data;
struct SingleRequest *k = &data->req;
+ int counter = 0;
do {
const char *name;
@@ -1068,6 +1072,11 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn,
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(conn, encoding, k->writer_stack);
if(!writer)