Blame SOURCES/CVE-2018-7159-Dissallow-empty-Content-Length.patch

93e6fe
From 350258965909f249f9c59823aac240313e0d0120 Mon Sep 17 00:00:00 2001
93e6fe
From: Olga Batyshkina <olga.batyshkina@virtual-solution.com>
93e6fe
Date: Wed, 19 Dec 2018 16:02:23 +0100
93e6fe
Subject: [PATCH] Disallow empty Content-Length
93e6fe
93e6fe
PR-URL: https://github.com/nodejs/http-parser/pull/459
93e6fe
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
93e6fe
---
93e6fe
 http_parser.c | 5 +++++
93e6fe
 test.c        | 7 +++++++
93e6fe
 2 files changed, 12 insertions(+)
93e6fe
93e6fe
diff --git a/http_parser.c b/http_parser.c
93e6fe
index cd5d0d5..228ada5 100644
93e6fe
--- a/http_parser.c
93e6fe
+++ b/http_parser.c
93e6fe
@@ -1740,6 +1740,11 @@ size_t http_parser_execute (http_parser *parser,
93e6fe
             case h_transfer_encoding_chunked:
93e6fe
               parser->flags |= F_CHUNKED;
93e6fe
               break;
93e6fe
+            case h_content_length:
93e6fe
+              /* do not allow empty content length */
93e6fe
+              SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
93e6fe
+              goto error;
93e6fe
+              break;
93e6fe
             default:
93e6fe
               break;
93e6fe
           }
93e6fe
diff --git a/test.c b/test.c
93e6fe
index 25c8f5f..c3fddd5 100644
93e6fe
--- a/test.c
93e6fe
+++ b/test.c
93e6fe
@@ -4182,6 +4182,13 @@ main (void)
93e6fe
   test_invalid_header_field_token_error(HTTP_RESPONSE);
93e6fe
   test_invalid_header_field_content_error(HTTP_RESPONSE);
93e6fe
 
93e6fe
+  test_simple_type(
93e6fe
+      "POST / HTTP/1.1\r\n"
93e6fe
+      "Content-Length:\r\n"  // empty
93e6fe
+      "\r\n",
93e6fe
+      HPE_INVALID_CONTENT_LENGTH,
93e6fe
+      HTTP_REQUEST);
93e6fe
+
93e6fe
   test_simple_type(
93e6fe
       "POST / HTTP/1.1\r\n"
93e6fe
       "Content-Length:  42 \r\n"  // Note the surrounding whitespace.