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

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