Blame SOURCES/0478-net-http-Error-out-on-headers-with-LF-without-CR.patch

d18179
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d18179
From: Daniel Axtens <dja@axtens.net>
d18179
Date: Tue, 8 Mar 2022 19:04:40 +1100
d18179
Subject: [PATCH] net/http: Error out on headers with LF without CR
d18179
d18179
In a similar vein to the previous patch, parse_line() would write
d18179
a NUL byte past the end of the buffer if there was an HTTP header
d18179
with a LF rather than a CRLF.
d18179
d18179
RFC-2616 says:
d18179
d18179
  Many HTTP/1.1 header field values consist of words separated by LWS
d18179
  or special characters. These special characters MUST be in a quoted
d18179
  string to be used within a parameter value (as defined in section 3.6).
d18179
d18179
We don't support quoted sections or continuation lines, etc.
d18179
d18179
If we see an LF that's not part of a CRLF, bail out.
d18179
d18179
Fixes: CVE-2022-28734
d18179
d18179
Signed-off-by: Daniel Axtens <dja@axtens.net>
d18179
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
d18179
(cherry picked from commit d232ad41ac4979a9de4d746e5fdff9caf0e303de)
d18179
(cherry picked from commit 8960e6d6137090a7e8c6592077da6e387a4ef972)
d18179
(cherry picked from commit 9b6b9398c90dd76ce0b935d21c4ecb8954c4b2b7)
d18179
(cherry picked from commit 939f44bae027c2f11fad5e730f1fda34b07a43a4)
d18179
---
d18179
 grub-core/net/http.c | 8 ++++++++
d18179
 1 file changed, 8 insertions(+)
d18179
d18179
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
d18179
index 443b8ffe87..e260e2defe 100644
d18179
--- a/grub-core/net/http.c
d18179
+++ b/grub-core/net/http.c
d18179
@@ -69,7 +69,15 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
d18179
   char *end = ptr + len;
d18179
   while (end > ptr && *(end - 1) == '\r')
d18179
     end--;
d18179
+
d18179
+  /* LF without CR. */
d18179
+  if (end == ptr + len)
d18179
+    {
d18179
+      data->errmsg = grub_strdup (_("invalid HTTP header - LF without CR"));
d18179
+      return GRUB_ERR_NONE;
d18179
+    }
d18179
   *end = 0;
d18179
+
d18179
   /* Trailing CRLF.  */
d18179
   if (data->in_chunk_len == 1)
d18179
     {