nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0292-font-Try-opening-fonts-from-the-bundled-memdisk.patch

b35c50
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b35c50
From: Chris Coulson <chris.coulson@canonical.com>
b35c50
Date: Wed, 16 Nov 2022 14:40:04 +0000
b35c50
Subject: [PATCH] font: Try opening fonts from the bundled memdisk
b35c50
b35c50
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
b35c50
---
b35c50
 grub-core/font/font.c | 48 +++++++++++++++++++++++++++++++-----------------
b35c50
 1 file changed, 31 insertions(+), 17 deletions(-)
b35c50
b35c50
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
b35c50
index e6616e610c..e421d1ae6f 100644
b35c50
--- a/grub-core/font/font.c
b35c50
+++ b/grub-core/font/font.c
b35c50
@@ -409,6 +409,27 @@ read_section_as_short (struct font_file_section *section,
b35c50
   return 0;
b35c50
 }
b35c50
 
b35c50
+static grub_file_t
b35c50
+try_open_from_prefix (const char *prefix, const char *filename)
b35c50
+{
b35c50
+  grub_file_t file;
b35c50
+  char *fullname, *ptr;
b35c50
+
b35c50
+  fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1
b35c50
+			  + sizeof ("/fonts/") + sizeof (".pf2"));
b35c50
+  if (!fullname)
b35c50
+    return 0;
b35c50
+  ptr = grub_stpcpy (fullname, prefix);
b35c50
+  ptr = grub_stpcpy (ptr, "/fonts/");
b35c50
+  ptr = grub_stpcpy (ptr, filename);
b35c50
+  ptr = grub_stpcpy (ptr, ".pf2");
b35c50
+  *ptr = 0;
b35c50
+
b35c50
+  file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
b35c50
+  grub_free (fullname);
b35c50
+  return file;
b35c50
+}
b35c50
+
b35c50
 /* Load a font and add it to the beginning of the global font list.
b35c50
    Returns 0 upon success, nonzero upon failure.  */
b35c50
 grub_font_t
b35c50
@@ -427,25 +448,18 @@ grub_font_load (const char *filename)
b35c50
     file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
b35c50
   else
b35c50
     {
b35c50
-      const char *prefix = grub_env_get ("prefix");
b35c50
-      char *fullname, *ptr;
b35c50
-      if (!prefix)
b35c50
+      file = try_open_from_prefix ("(memdisk)", filename);
b35c50
+      if (!file)
b35c50
 	{
b35c50
-	  grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
b35c50
-		      "prefix");
b35c50
-	  goto fail;
b35c50
+	  const char *prefix = grub_env_get ("prefix");
b35c50
+	  if (!prefix)
b35c50
+	    {
b35c50
+	      grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
b35c50
+			  "prefix");
b35c50
+	      goto fail;
b35c50
+	    }
b35c50
+	  file = try_open_from_prefix (prefix, filename);
b35c50
 	}
b35c50
-      fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1
b35c50
-			      + sizeof ("/fonts/") + sizeof (".pf2"));
b35c50
-      if (!fullname)
b35c50
-	goto fail;
b35c50
-      ptr = grub_stpcpy (fullname, prefix);
b35c50
-      ptr = grub_stpcpy (ptr, "/fonts/");
b35c50
-      ptr = grub_stpcpy (ptr, filename);
b35c50
-      ptr = grub_stpcpy (ptr, ".pf2");
b35c50
-      *ptr = 0;
b35c50
-      file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
b35c50
-      grub_free (fullname);
b35c50
     }
b35c50
   if (!file)
b35c50
     goto fail;