Blame SOURCES/0432-commands-menuentry-Fix-quoting-in-setparams_prefix.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Daniel Axtens <dja@axtens.net>
80913e
Date: Fri, 22 Jan 2021 17:10:48 +1100
80913e
Subject: [PATCH] commands/menuentry: Fix quoting in setparams_prefix()
80913e
80913e
Commit 9acdcbf32542 (use single quotes in menuentry setparams command)
80913e
says that expressing a quoted single quote will require 3 characters. It
80913e
actually requires (and always did require!) 4 characters:
80913e
80913e
  str: a'b => a'\''b
80913e
  len:  3  => 6 (2 for the letters + 4 for the quote)
80913e
80913e
This leads to not allocating enough memory and thus out of bounds writes
80913e
that have been observed to cause heap corruption.
80913e
80913e
Allocate 4 bytes for each single quote.
80913e
80913e
Commit 22e7dbb2bb81 (Fix quoting in legacy parser.) does the same
80913e
quoting, but it adds 3 as extra overhead on top of the single byte that
80913e
the quote already needs. So it's correct.
80913e
80913e
Fixes: CVE-2021-20233
80913e
Fixes: 9acdcbf32542 (use single quotes in menuentry setparams command)
80913e
80913e
Signed-off-by: Daniel Axtens <dja@axtens.net>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/commands/menuentry.c | 2 +-
80913e
 1 file changed, 1 insertion(+), 1 deletion(-)
80913e
80913e
diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c
b32e65
index 4b5fcf2ce..7a533b974 100644
80913e
--- a/grub-core/commands/menuentry.c
80913e
+++ b/grub-core/commands/menuentry.c
80913e
@@ -239,7 +239,7 @@ setparams_prefix (int argc, char **args)
80913e
       len += 3; /* 3 = 1 space + 2 quotes */
80913e
       p = args[i];
80913e
       while (*p)
80913e
-	len += (*p++ == '\'' ? 3 : 1);
80913e
+	len += (*p++ == '\'' ? 4 : 1);
80913e
     }
80913e
 
80913e
   result = grub_malloc (len + 2);