summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2019-12-01 15:22:25 -0800
committerCosimo Cecchi <cosimoc@gnome.org>2019-12-01 15:36:25 -0800
commit9661683379806e2bad6a52ce6dde776a33f4f981 (patch)
treea7e11c04c62ae105ebae57a19f8e699bca022224 /src
parent4d548988b61aad297219aa5ebfc68158b6d05b18 (diff)
downloadgnome-font-viewer-9661683379806e2bad6a52ce6dde776a33f4f981.tar.gz
Fallback to basename when no family name (CVE-2019-19308)
Instead of possibly returning an empty string, which will cause issues later on. We store the GFile that was loaded to create the FT_Face into its generic client data structure, and load the basename from it when we don't have a family name. https://gitlab.gnome.org/GNOME/gnome-font-viewer/issues/17
Diffstat (limited to 'src')
-rw-r--r--src/sushi-font-loader.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/sushi-font-loader.c b/src/sushi-font-loader.c
index e7da560..df28c1a 100644
--- a/src/sushi-font-loader.c
+++ b/src/sushi-font-loader.c
@@ -67,6 +67,13 @@ font_load_job_free (FontLoadJob *job)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FontLoadJob, font_load_job_free)
+static void
+face_data_finalizer (void *object)
+{
+ FT_Face face = object;
+ g_clear_object (&face->generic.data);
+}
+
static FT_Face
create_face_from_contents (FontLoadJob *job,
gchar **contents,
@@ -88,6 +95,9 @@ create_face_from_contents (FontLoadJob *job,
return NULL;
}
+ retval->generic.data = g_object_ref (job->file);
+ retval->generic.finalizer = face_data_finalizer;
+
*contents = g_steal_pointer (&job->face_contents);
return retval;
}
@@ -181,8 +191,22 @@ gchar *
sushi_get_font_name (FT_Face face,
gboolean short_form)
{
- if (short_form && g_strcmp0 (face->style_name, "Regular") == 0)
- return g_strdup (face->family_name);
+ const char *style_name = face->style_name;
+ const char *family_name = face->family_name;
+
+ if (family_name == NULL) {
+ /* Try to get the basename of the file this was loaded from */
+ GFile *file = face->generic.data;
+ if (G_IS_FILE (file))
+ return g_file_get_basename (file);
+
+ /* Use an empty string as the last fallback */
+ return g_strdup ("");
+ }
+
+ if (style_name == NULL ||
+ (short_form && g_strcmp0 (style_name, "Regular") == 0))
+ return g_strdup (family_name);
- return g_strconcat (face->family_name, ", ", face->style_name, NULL);
+ return g_strconcat (family_name, ", ", style_name, NULL);
}