Blame SOURCES/0291-normal-charset-Fix-an-integer-overflow-in-grub_unico.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Zhang Boyang <zhangboyang.id@gmail.com>
fd0330
Date: Fri, 28 Oct 2022 21:31:39 +0800
fd0330
Subject: [PATCH] normal/charset: Fix an integer overflow in
fd0330
 grub_unicode_aglomerate_comb()
fd0330
fd0330
The out->ncomb is a bit-field of 8 bits. So, the max possible value is 255.
fd0330
However, code in grub_unicode_aglomerate_comb() doesn't check for an
fd0330
overflow when incrementing out->ncomb. If out->ncomb is already 255,
fd0330
after incrementing it will get 0 instead of 256, and cause illegal
fd0330
memory access in subsequent processing.
fd0330
fd0330
This patch introduces GRUB_UNICODE_NCOMB_MAX to represent the max
fd0330
acceptable value of ncomb. The code now checks for this limit and
fd0330
ignores additional combining characters when limit is reached.
fd0330
fd0330
Reported-by: Daniel Axtens <dja@axtens.net>
fd0330
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
fd0330
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
fd0330
(cherry picked from commit da90d62316a3b105d2fbd7334d6521936bd6dcf6)
fd0330
---
fd0330
 grub-core/normal/charset.c | 3 +++
fd0330
 include/grub/unicode.h     | 2 ++
fd0330
 2 files changed, 5 insertions(+)
fd0330
fd0330
diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c
fd0330
index 7a5a7c153c..c243ca6dae 100644
fd0330
--- a/grub-core/normal/charset.c
fd0330
+++ b/grub-core/normal/charset.c
fd0330
@@ -472,6 +472,9 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen,
fd0330
 	  if (!haveout)
fd0330
 	    continue;
fd0330
 
fd0330
+	  if (out->ncomb == GRUB_UNICODE_NCOMB_MAX)
fd0330
+	    continue;
fd0330
+
fd0330
 	  if (comb_type == GRUB_UNICODE_COMB_MC
fd0330
 	      || comb_type == GRUB_UNICODE_COMB_ME
fd0330
 	      || comb_type == GRUB_UNICODE_COMB_MN)
fd0330
diff --git a/include/grub/unicode.h b/include/grub/unicode.h
fd0330
index 4de986a857..c4f6fca043 100644
fd0330
--- a/include/grub/unicode.h
fd0330
+++ b/include/grub/unicode.h
fd0330
@@ -147,7 +147,9 @@ struct grub_unicode_glyph
fd0330
   grub_uint8_t bidi_level:6; /* minimum: 6 */
fd0330
   enum grub_bidi_type bidi_type:5; /* minimum: :5 */
fd0330
 
fd0330
+#define GRUB_UNICODE_NCOMB_MAX ((1 << 8) - 1)
fd0330
   unsigned ncomb:8;
fd0330
+
fd0330
   /* Hint by unicode subsystem how wide this character usually is.
fd0330
      Real width is determined by font. Set only in UTF-8 stream.  */
fd0330
   int estimated_width:8;