Fix crashes in various GParamSpec creation functions 36/309036/1
authorJinWang An <jinwang.an@samsung.com>
Thu, 4 Apr 2024 05:45:57 +0000 (14:45 +0900)
committerJinWang An <jinwang.an@samsung.com>
Thu, 4 Apr 2024 05:45:57 +0000 (14:45 +0900)
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 <jinwang.an@samsung.com>
gobject/gparamspecs.c

index 17b8606..f4a39f1 100644 (file)
@@ -1884,6 +1884,8 @@ g_param_spec_char (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (cspec == NULL)
+    return NULL;
   
   cspec->minimum = minimum;
   cspec->maximum = maximum;
@@ -1924,6 +1926,8 @@ g_param_spec_uchar (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (uspec == NULL)
+    return NULL;
   
   uspec->minimum = minimum;
   uspec->maximum = maximum;
@@ -1966,6 +1970,8 @@ g_param_spec_boolean (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (bspec == NULL)
+    return NULL;
   
   bspec->default_value = default_value;
   
@@ -2006,6 +2012,8 @@ g_param_spec_int (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (ispec == NULL)
+    return NULL;
   
   ispec->minimum = minimum;
   ispec->maximum = maximum;
@@ -2048,6 +2056,8 @@ g_param_spec_uint (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (uspec == NULL)
+    return NULL;
   
   uspec->minimum = minimum;
   uspec->maximum = maximum;
@@ -2090,6 +2100,8 @@ g_param_spec_long (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (lspec == NULL)
+    return NULL;
   
   lspec->minimum = minimum;
   lspec->maximum = maximum;
@@ -2133,6 +2145,8 @@ g_param_spec_ulong (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (uspec == NULL)
+    return NULL;
   
   uspec->minimum = minimum;
   uspec->maximum = maximum;
@@ -2175,6 +2189,8 @@ g_param_spec_int64 (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (lspec == NULL)
+    return NULL;
   
   lspec->minimum = minimum;
   lspec->maximum = maximum;
@@ -2218,6 +2234,8 @@ g_param_spec_uint64 (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (uspec == NULL)
+    return NULL;
   
   uspec->minimum = minimum;
   uspec->maximum = maximum;
@@ -2256,6 +2274,8 @@ g_param_spec_unichar (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (uspec == NULL)
+    return NULL;
   
   uspec->default_value = default_value;
   
@@ -2300,7 +2320,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;
@@ -2346,6 +2368,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;
@@ -2388,6 +2412,8 @@ g_param_spec_float (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (fspec == NULL)
+    return NULL;
   
   fspec->minimum = minimum;
   fspec->maximum = maximum;
@@ -2431,6 +2457,8 @@ g_param_spec_double (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (dspec == NULL)
+    return NULL;
   
   dspec->minimum = minimum;
   dspec->maximum = maximum;
@@ -2465,6 +2493,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);
@@ -2503,6 +2533,8 @@ g_param_spec_param (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (pspec == NULL)
+    return NULL;
 
   G_PARAM_SPEC (pspec)->value_type = param_type;
   
@@ -2541,6 +2573,8 @@ g_param_spec_boxed (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (bspec == NULL)
+    return NULL;
 
   G_PARAM_SPEC (bspec)->value_type = boxed_type;
   
@@ -2575,6 +2609,8 @@ g_param_spec_pointer (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (pspec == NULL)
+    return NULL;
 
   return G_PARAM_SPEC (pspec);
 }
@@ -2611,6 +2647,8 @@ g_param_spec_gtype (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (tspec == NULL)
+    return NULL;
 
   tspec->is_a_type = is_a_type;
 
@@ -2651,6 +2689,8 @@ g_param_spec_value_array (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (aspec == NULL)
+    return NULL;
 
   if (element_spec)
     {
@@ -2692,6 +2732,8 @@ g_param_spec_object (const gchar *name,
                                 nick,
                                 blurb,
                                 flags);
+  if (ospec == NULL)
+    return NULL;
 
   G_PARAM_SPEC (ospec)->value_type = object_type;
   
@@ -2734,6 +2776,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);
@@ -2781,6 +2825,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)