dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0437-term-gfxterm-Don-t-set-up-a-font-with-glyphs-that-ar.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Daniel Axtens <dja@axtens.net>
80913e
Date: Fri, 15 Jan 2021 20:03:20 +1100
80913e
Subject: [PATCH] term/gfxterm: Don't set up a font with glyphs that are too
80913e
 big
80913e
80913e
Catch the case where we have a font so big that it causes the number of
80913e
rows or columns to be 0. Currently we continue and allocate a
80913e
virtual_screen.text_buffer of size 0. We then try to use that for glpyhs
80913e
and things go badly.
80913e
80913e
On the emu platform, malloc() may give us a valid pointer, in which case
80913e
we'll access heap memory which we shouldn't. Alternatively, it may give us
80913e
NULL, in which case we'll crash. For other platforms, if I understand
80913e
grub_memalign() correctly, we will receive a valid but small allocation
80913e
that we will very likely later overrun.
80913e
80913e
Prevent the creation of a virtual screen that isn't at least 40 cols
80913e
by 12 rows. This is arbitrary, but it seems that if your width or height
80913e
is half a standard 80x24 terminal, you're probably going to struggle to
80913e
read anything anyway.
80913e
80913e
Signed-off-by: Daniel Axtens <dja@axtens.net>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/term/gfxterm.c | 9 +++++++++
80913e
 1 file changed, 9 insertions(+)
80913e
80913e
diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c
80913e
index af7c090a3e7..b40fcce9151 100644
80913e
--- a/grub-core/term/gfxterm.c
80913e
+++ b/grub-core/term/gfxterm.c
80913e
@@ -232,6 +232,15 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
80913e
   virtual_screen.columns = virtual_screen.width / virtual_screen.normal_char_width;
80913e
   virtual_screen.rows = virtual_screen.height / virtual_screen.normal_char_height;
80913e
 
80913e
+  /*
80913e
+   * There must be a minimum number of rows and columns for the screen to
80913e
+   * make sense. Arbitrarily pick half of 80x24. If either dimensions is 0
80913e
+   * we would allocate 0 bytes for the text_buffer.
80913e
+   */
80913e
+  if (virtual_screen.columns < 40 || virtual_screen.rows < 12)
80913e
+    return grub_error (GRUB_ERR_BAD_FONT,
80913e
+		       "font: glyphs too large to fit on screen");
80913e
+
80913e
   /* Allocate memory for text buffer.  */
80913e
   virtual_screen.text_buffer =
80913e
     (struct grub_colored_char *) grub_malloc (virtual_screen.columns