summaryrefslogtreecommitdiff
path: root/src/xsettings.c
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-05-15 09:30:07 +0800
committerPo Lu <luangruo@yahoo.com>2022-05-15 09:30:07 +0800
commit8e592973782e38be75faed39f557642bbae6aec5 (patch)
treecc10539ed6995f6d966cefd7f48006608f1c80a3 /src/xsettings.c
parent003dc93f93994c1fc568a7844623fa65f9d33448 (diff)
downloademacs-8e592973782e38be75faed39f557642bbae6aec5.tar.gz
emacs-8e592973782e38be75faed39f557642bbae6aec5.tar.bz2
emacs-8e592973782e38be75faed39f557642bbae6aec5.zip
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)
Diffstat (limited to 'src/xsettings.c')
-rw-r--r--src/xsettings.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/xsettings.c b/src/xsettings.c
index e71887e03d9..16625bd229f 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,