1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
From: Chris Coulson <chris.coulson@canonical.com>
Date: Wed, 16 Nov 2022 14:40:04 +0000
Subject: font: Try opening fonts from the bundled memdisk
---
grub-core/font/font.c | 48 +++++++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index e6616e6..e421d1a 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -409,6 +409,27 @@ read_section_as_short (struct font_file_section *section,
return 0;
}
+static grub_file_t
+try_open_from_prefix (const char *prefix, const char *filename)
+{
+ grub_file_t file;
+ char *fullname, *ptr;
+
+ fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1
+ + sizeof ("/fonts/") + sizeof (".pf2"));
+ if (!fullname)
+ return 0;
+ ptr = grub_stpcpy (fullname, prefix);
+ ptr = grub_stpcpy (ptr, "/fonts/");
+ ptr = grub_stpcpy (ptr, filename);
+ ptr = grub_stpcpy (ptr, ".pf2");
+ *ptr = 0;
+
+ file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
+ grub_free (fullname);
+ return file;
+}
+
/* Load a font and add it to the beginning of the global font list.
Returns 0 upon success, nonzero upon failure. */
grub_font_t
@@ -427,25 +448,18 @@ grub_font_load (const char *filename)
file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
else
{
- const char *prefix = grub_env_get ("prefix");
- char *fullname, *ptr;
- if (!prefix)
+ file = try_open_from_prefix ("(memdisk)", filename);
+ if (!file)
{
- grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
- "prefix");
- goto fail;
+ const char *prefix = grub_env_get ("prefix");
+ if (!prefix)
+ {
+ grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
+ "prefix");
+ goto fail;
+ }
+ file = try_open_from_prefix (prefix, filename);
}
- fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1
- + sizeof ("/fonts/") + sizeof (".pf2"));
- if (!fullname)
- goto fail;
- ptr = grub_stpcpy (fullname, prefix);
- ptr = grub_stpcpy (ptr, "/fonts/");
- ptr = grub_stpcpy (ptr, filename);
- ptr = grub_stpcpy (ptr, ".pf2");
- *ptr = 0;
- file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
- grub_free (fullname);
}
if (!file)
goto fail;
|