]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
font: Check return value of grub_malloc() in ascii_glyph_lookup()
authorZhang Boyang <zhangboyang.id@gmail.com>
Mon, 5 Dec 2022 11:29:36 +0000 (19:29 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 10 Jan 2023 15:01:01 +0000 (16:01 +0100)
There is a problem in ascii_glyph_lookup(). It doesn't check the return
value of grub_malloc(). If memory can't be allocated, then NULL pointer
will be written to.

This patch fixes the problem by fallbacking to unknown_glyph when
grub_malloc() returns NULL.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/font/font.c

index 3821937e6435fdd672df8821de51a7b35da2fa56..19a47f873c5dcf55570c1be21fac07f5175f8259 100644 (file)
@@ -131,6 +131,11 @@ ascii_glyph_lookup (grub_uint32_t code)
        {
          ascii_font_glyph[current] =
            grub_malloc (sizeof (struct grub_font_glyph) + ASCII_BITMAP_SIZE);
+         if (ascii_font_glyph[current] == NULL)
+           {
+             ascii_font_glyph[current] = unknown_glyph;
+             continue;
+           }
 
          ascii_font_glyph[current]->width = 8;
          ascii_font_glyph[current]->height = 16;