nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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