emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 8e59297378: Prevent crashes trying to access nonexistent key


From: Po Lu
Subject: master 8e59297378: Prevent crashes trying to access nonexistent key
Date: Sat, 14 May 2022 21:30:29 -0400 (EDT)

branch: master
commit 8e592973782e38be75faed39f557642bbae6aec5
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Prevent crashes trying to access nonexistent key
    
    * src/xsettings.c (xg_settings_key_valid_p): New function.
    (apply_gsettings_font_antialias): Test that `font-aliasing' is
    actually available.  (bug#55416)
---
 src/xsettings.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/xsettings.c b/src/xsettings.c
index e71887e03d..16625bd229 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -268,17 +268,47 @@ apply_gsettings_font_hinting (GSettings *settings)
     }
 }
 
+static bool
+xg_settings_key_valid_p (GSettings *settings, const char *key)
+{
+#ifdef GLIB_VERSION_2_32
+  GSettingsSchema *schema;
+  bool rc;
+
+  g_object_get (G_OBJECT (settings),
+               "settings-schema", &schema,
+               NULL);
+
+  if (!schema)
+    return false;
+
+  rc = g_settings_schema_has_key (schema, key);
+  g_settings_schema_unref (schema);
+
+  return rc;
+#else
+  return false;
+#endif
+}
+
 /* Apply changes in the antialiasing system setting.  */
 static void
 apply_gsettings_font_antialias (GSettings *settings)
 {
-  GVariant *val = g_settings_get_value (settings, GSETTINGS_FONT_ANTIALIASING);
+  GVariant *val;
+  const char *antialias;
+
+  if (!xg_settings_key_valid_p (settings, GSETTINGS_FONT_ANTIALIASING))
+    return;
+
+  val = g_settings_get_value (settings, GSETTINGS_FONT_ANTIALIASING);
+
   if (val)
     {
       g_variant_ref_sink (val);
       if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
        {
-         const char *antialias = g_variant_get_string (val, NULL);
+         antialias = g_variant_get_string (val, NULL);
 
          if (!strcmp (antialias, "none"))
            cairo_font_options_set_antialias (font_options,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]