All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Boyang <zhangboyang.id@gmail.com>
To: grub-devel@gnu.org
Cc: Zhang Boyang <zhangboyang.id@gmail.com>
Subject: [PATCH 1/5] font: Check return value of grub_malloc() in ascii_glyph_lookup()
Date: Mon,  5 Dec 2022 19:29:36 +0800	[thread overview]
Message-ID: <20221205112940.246486-2-zhangboyang.id@gmail.com> (raw)
In-Reply-To: <20221205112940.246486-1-zhangboyang.id@gmail.com>

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 in case of
grub_malloc() returns NULL.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
---
 grub-core/font/font.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index 3821937e6..19a47f873 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -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;
-- 
2.30.2



  reply	other threads:[~2022-12-05 11:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 11:29 [PATCH 0/5] Font fixes and preliminary HiDPI support Zhang Boyang
2022-12-05 11:29 ` Zhang Boyang [this message]
2022-12-13 17:16   ` [PATCH 1/5] font: Check return value of grub_malloc() in ascii_glyph_lookup() Daniel Kiper
2022-12-05 11:29 ` [PATCH 2/5] font: Assign null_font to unknown_glyph Zhang Boyang
2022-12-13 17:17   ` Daniel Kiper
2022-12-05 11:29 ` [PATCH 3/5] font: Reject fonts with negative max_char_width or max_char_height Zhang Boyang
2022-12-13 17:17   ` Daniel Kiper
2022-12-05 11:29 ` [PATCH 4/5] font: Add font scaling feature to grub_font_draw_glyph() Zhang Boyang
2022-12-05 11:42   ` Zhang Boyang
2022-12-05 11:29 ` [PATCH 5/5] term/gfxterm: Preliminary HiDPI support Zhang Boyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221205112940.246486-2-zhangboyang.id@gmail.com \
    --to=zhangboyang.id@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.