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

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