Blame SOURCES/CVE-2018-12121.patch

6899e0
From 05da7fb51cda374ae351829f67018924f931f18b Mon Sep 17 00:00:00 2001
6899e0
From: Sergio Correia <scorreia@redhat.com>
6899e0
Date: Tue, 18 Feb 2020 09:10:18 -0300
6899e0
Subject: [PATCH] CVE-2018-12121
6899e0
6899e0
---
6899e0
 http_parser.c | 15 +++++++++++----
6899e0
 http_parser.h |  3 +++
6899e0
 2 files changed, 14 insertions(+), 4 deletions(-)
6899e0
014b88
diff --git a/http_parser.c b/http_parser.c
014b88
index f9991c3..aef4437 100644
014b88
--- a/http_parser.c
014b88
+++ b/http_parser.c
014b88
@@ -25,6 +25,8 @@
014b88
 #include <string.h>
014b88
 #include <limits.h>
014b88
 
014b88
+static uint32_t max_header_size = HTTP_MAX_HEADER_SIZE;
014b88
+
014b88
 #ifndef ULLONG_MAX
014b88
 # define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */
014b88
 #endif
014b88
@@ -137,20 +139,20 @@ do {                                                                 \
014b88
 } while (0)
014b88
 
014b88
 /* Don't allow the total size of the HTTP headers (including the status
014b88
- * line) to exceed HTTP_MAX_HEADER_SIZE.  This check is here to protect
014b88
+ * line) to exceed max_header_size.  This check is here to protect
014b88
  * embedders against denial-of-service attacks where the attacker feeds
014b88
  * us a never-ending header that the embedder keeps buffering.
014b88
  *
014b88
  * This check is arguably the responsibility of embedders but we're doing
014b88
  * it on the embedder's behalf because most won't bother and this way we
014b88
- * make the web a little safer.  HTTP_MAX_HEADER_SIZE is still far bigger
014b88
+ * make the web a little safer.  max_header_size is still far bigger
014b88
  * than any reasonable request or response so this should never affect
014b88
  * day-to-day operation.
014b88
  */
014b88
 #define COUNT_HEADER_SIZE(V)                                         \
014b88
 do {                                                                 \
014b88
   parser->nread += (V);                                              \
014b88
-  if (UNLIKELY(parser->nread > (HTTP_MAX_HEADER_SIZE))) {            \
014b88
+  if (UNLIKELY(parser->nread > (max_header_size))) {                 \
014b88
     SET_ERRNO(HPE_HEADER_OVERFLOW);                                  \
014b88
     goto error;                                                      \
014b88
   }                                                                  \
014b88
@@ -1471,7 +1473,7 @@ reexecute:
014b88
               const char* p_lf;
014b88
               size_t limit = data + len - p;
014b88
 
014b88
-              limit = MIN(limit, HTTP_MAX_HEADER_SIZE);
014b88
+              limit = MIN(limit, max_header_size);
014b88
 
014b88
               p_cr = (const char*) memchr(p, CR, limit);
014b88
               p_lf = (const char*) memchr(p, LF, limit);
014b88
@@ -2438,3 +2440,8 @@ http_parser_version(void) {
014b88
          HTTP_PARSER_VERSION_MINOR * 0x00100 |
014b88
          HTTP_PARSER_VERSION_PATCH * 0x00001;
014b88
 }
014b88
+
014b88
+void
014b88
+http_parser_set_max_header_size(uint32_t size) {
014b88
+  max_header_size = size;
014b88
+}
014b88
diff --git a/http_parser.h b/http_parser.h
014b88
index 1fbf30e..ea7bafe 100644
014b88
--- a/http_parser.h
014b88
+++ b/http_parser.h
014b88
@@ -427,6 +427,9 @@ void http_parser_pause(http_parser *parser, int paused);
014b88
 /* Checks if this is the final chunk of the body. */
014b88
 int http_body_is_final(const http_parser *parser);
014b88
 
014b88
+/* Change the maximum header size provided at compile time. */
014b88
+void http_parser_set_max_header_size(uint32_t size);
014b88
+
014b88
 #ifdef __cplusplus
014b88
 }
014b88
 #endif
6899e0
-- 
6899e0
2.18.2
6899e0