]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
normal/charset: Fix array out-of-bounds formatting unicode for display
authorDaniel Axtens <dja@axtens.net>
Tue, 13 Jul 2021 03:24:38 +0000 (13:24 +1000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 7 Jun 2022 14:39:32 +0000 (16:39 +0200)
In some cases attempting to display arbitrary binary strings leads
to ASAN splats reading the widthspec array out of bounds.

Check the index. If it would be out of bounds, return a width of 1.
I don't know if that's strictly correct, but we're not really expecting
great display of arbitrary binary data, and it's certainly not worse than
an OOB read.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/normal/charset.c

index 7778f1a9932e61d6bc985ec35ac8f86b49706afb..000e687bdc59fee640ea42655498e0fdf9ad8752 100644 (file)
@@ -395,6 +395,8 @@ grub_unicode_estimate_width (const struct grub_unicode_glyph *c)
 {
   if (grub_unicode_get_comb_type (c->base))
     return 0;
+  if (((unsigned long) (c->base >> 3)) >= ARRAY_SIZE (widthspec))
+    return 1;
   if (widthspec[c->base >> 3] & (1 << (c->base & 7)))
     return 2;
   else