From 0b0c2f93c9e1b1aa189650066c620b3f4f3ee467 Mon Sep 17 00:00:00 2001 From: JinWang An Date: Thu, 4 Apr 2024 14:45:57 +0900 Subject: [PATCH] Fix crashes in various GParamSpec creation functions Add NULL check and return after calls to g_param_spec_internal in GParamSpec creation functions. This avoids glib crashing due to things like badly named properties. https://bugzilla.gnome.org/show_bug.cgi?id=707887 Change-Id: I9c420dbc008d60aa2e3db3386da36a350fe79e10 Signed-off-by: JinWang An --- gobject/gparamspecs.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/gobject/gparamspecs.c b/gobject/gparamspecs.c index 12a8124..ae7e22f 100644 --- a/gobject/gparamspecs.c +++ b/gobject/gparamspecs.c @@ -1861,6 +1861,8 @@ g_param_spec_char (const gchar *name, nick, blurb, flags); + if (cspec == NULL) + return NULL; cspec->minimum = minimum; cspec->maximum = maximum; @@ -1901,6 +1903,8 @@ g_param_spec_uchar (const gchar *name, nick, blurb, flags); + if (uspec == NULL) + return NULL; uspec->minimum = minimum; uspec->maximum = maximum; @@ -1943,6 +1947,8 @@ g_param_spec_boolean (const gchar *name, nick, blurb, flags); + if (bspec == NULL) + return NULL; bspec->default_value = default_value; @@ -1983,6 +1989,8 @@ g_param_spec_int (const gchar *name, nick, blurb, flags); + if (ispec == NULL) + return NULL; ispec->minimum = minimum; ispec->maximum = maximum; @@ -2025,6 +2033,8 @@ g_param_spec_uint (const gchar *name, nick, blurb, flags); + if (uspec == NULL) + return NULL; uspec->minimum = minimum; uspec->maximum = maximum; @@ -2067,6 +2077,8 @@ g_param_spec_long (const gchar *name, nick, blurb, flags); + if (lspec == NULL) + return NULL; lspec->minimum = minimum; lspec->maximum = maximum; @@ -2110,6 +2122,8 @@ g_param_spec_ulong (const gchar *name, nick, blurb, flags); + if (uspec == NULL) + return NULL; uspec->minimum = minimum; uspec->maximum = maximum; @@ -2152,6 +2166,8 @@ g_param_spec_int64 (const gchar *name, nick, blurb, flags); + if (lspec == NULL) + return NULL; lspec->minimum = minimum; lspec->maximum = maximum; @@ -2195,6 +2211,8 @@ g_param_spec_uint64 (const gchar *name, nick, blurb, flags); + if (uspec == NULL) + return NULL; uspec->minimum = minimum; uspec->maximum = maximum; @@ -2233,6 +2251,8 @@ g_param_spec_unichar (const gchar *name, nick, blurb, flags); + if (uspec == NULL) + return NULL; uspec->default_value = default_value; @@ -2277,7 +2297,9 @@ g_param_spec_enum (const gchar *name, nick, blurb, flags); - + if (espec == NULL) + return NULL; + espec->enum_class = enum_class; espec->default_value = default_value; G_PARAM_SPEC (espec)->value_type = enum_type; @@ -2323,6 +2345,8 @@ g_param_spec_flags (const gchar *name, nick, blurb, flags); + if (fspec == NULL) + return NULL; fspec->flags_class = flags_class; fspec->default_value = default_value; @@ -2365,6 +2389,8 @@ g_param_spec_float (const gchar *name, nick, blurb, flags); + if (fspec == NULL) + return NULL; fspec->minimum = minimum; fspec->maximum = maximum; @@ -2408,6 +2434,8 @@ g_param_spec_double (const gchar *name, nick, blurb, flags); + if (dspec == NULL) + return NULL; dspec->minimum = minimum; dspec->maximum = maximum; @@ -2442,6 +2470,8 @@ g_param_spec_string (const gchar *name, nick, blurb, flags); + if (sspec == NULL) + return NULL; g_free (sspec->default_value); sspec->default_value = g_strdup (default_value); @@ -2480,6 +2510,8 @@ g_param_spec_param (const gchar *name, nick, blurb, flags); + if (pspec == NULL) + return NULL; G_PARAM_SPEC (pspec)->value_type = param_type; @@ -2518,6 +2550,8 @@ g_param_spec_boxed (const gchar *name, nick, blurb, flags); + if (bspec == NULL) + return NULL; G_PARAM_SPEC (bspec)->value_type = boxed_type; @@ -2552,6 +2586,8 @@ g_param_spec_pointer (const gchar *name, nick, blurb, flags); + if (pspec == NULL) + return NULL; return G_PARAM_SPEC (pspec); } @@ -2588,6 +2624,8 @@ g_param_spec_gtype (const gchar *name, nick, blurb, flags); + if (tspec == NULL) + return NULL; tspec->is_a_type = is_a_type; @@ -2628,6 +2666,8 @@ g_param_spec_value_array (const gchar *name, nick, blurb, flags); + if (aspec == NULL) + return NULL; if (element_spec) { @@ -2669,6 +2709,8 @@ g_param_spec_object (const gchar *name, nick, blurb, flags); + if (ospec == NULL) + return NULL; G_PARAM_SPEC (ospec)->value_type = object_type; @@ -2711,6 +2753,8 @@ g_param_spec_override (const gchar *name, pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE, name, NULL, NULL, overridden->flags); + if (pspec == NULL) + return NULL; pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden); G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden); @@ -2758,6 +2802,8 @@ g_param_spec_variant (const gchar *name, nick, blurb, flags); + if (vspec == NULL) + return NULL; vspec->type = g_variant_type_copy (type); if (default_value) -- 2.7.4