From: Po Lu Date: Sun, 15 May 2022 01:30:07 +0000 (+0800) Subject: Prevent crashes trying to access nonexistent key X-Git-Tag: emacs-29.0.90~1910^2~685 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8e592973782e38be75faed39f557642bbae6aec5;p=emacs.git 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) --- 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,