From 1856990c2bbe52af040e3059cd055804eac9d601 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 27 Dec 2019 19:53:08 +0100 Subject: [PATCH] libgimp*: check all return values of g_param_spec_internal() like in the fix for issue #4392. Remove the reference to the issue from gimp_param_spec_layer() because we can't have it in all places that now do checks. --- libgimp/gimpparamspecs-body.c | 22 +++++++++++++++++----- libgimpbase/gimpparamspecs.c | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libgimp/gimpparamspecs-body.c b/libgimp/gimpparamspecs-body.c index bdbf47e1d4..788aa9f7c7 100644 --- a/libgimp/gimpparamspecs-body.c +++ b/libgimp/gimpparamspecs-body.c @@ -123,6 +123,8 @@ gimp_param_spec_image (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_IMAGE, name, nick, blurb, flags); + g_return_val_if_fail (ispec, NULL); + ispec->none_ok = none_ok ? TRUE : FALSE; return G_PARAM_SPEC (ispec); @@ -228,6 +230,8 @@ gimp_param_spec_item (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_ITEM, name, nick, blurb, flags); + g_return_val_if_fail (ispec, NULL); + ispec->none_ok = none_ok; return G_PARAM_SPEC (ispec); @@ -306,6 +310,8 @@ gimp_param_spec_drawable (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_DRAWABLE, name, nick, blurb, flags); + g_return_val_if_fail (ispec, NULL); + ispec->none_ok = none_ok ? TRUE : FALSE; return G_PARAM_SPEC (ispec); @@ -383,11 +389,7 @@ gimp_param_spec_layer (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_LAYER, name, nick, blurb, flags); - /* g_param_spec_internal() may fail if for instance @name is invalid. - * We don't want to dereference the pointer and segfault in such a - * case, so let's just fail here. - * See #4392. - */ + g_return_val_if_fail (ispec, NULL); ispec->none_ok = none_ok ? TRUE : FALSE; @@ -468,6 +470,8 @@ gimp_param_spec_channel (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_CHANNEL, name, nick, blurb, flags); + g_return_val_if_fail (ispec, NULL); + ispec->none_ok = none_ok ? TRUE : FALSE; return G_PARAM_SPEC (ispec); @@ -546,6 +550,8 @@ gimp_param_spec_layer_mask (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_LAYER_MASK, name, nick, blurb, flags); + g_return_val_if_fail (ispec, NULL); + ispec->none_ok = none_ok ? TRUE : FALSE; return G_PARAM_SPEC (ispec); @@ -624,6 +630,8 @@ gimp_param_spec_selection (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_SELECTION, name, nick, blurb, flags); + g_return_val_if_fail (ispec, NULL); + ispec->none_ok = none_ok ? TRUE : FALSE; return G_PARAM_SPEC (ispec); @@ -702,6 +710,8 @@ gimp_param_spec_vectors (const gchar *name, ispec = g_param_spec_internal (GIMP_TYPE_PARAM_VECTORS, name, nick, blurb, flags); + g_return_val_if_fail (ispec, NULL); + ispec->none_ok = none_ok ? TRUE : FALSE; return G_PARAM_SPEC (ispec); @@ -807,6 +817,8 @@ gimp_param_spec_display (const gchar *name, dspec = g_param_spec_internal (GIMP_TYPE_PARAM_DISPLAY, name, nick, blurb, flags); + g_return_val_if_fail (dspec, NULL); + dspec->none_ok = none_ok ? TRUE : FALSE; return G_PARAM_SPEC (dspec); diff --git a/libgimpbase/gimpparamspecs.c b/libgimpbase/gimpparamspecs.c index c0c4d5220c..40135d4169 100644 --- a/libgimpbase/gimpparamspecs.c +++ b/libgimpbase/gimpparamspecs.c @@ -1448,6 +1448,8 @@ gimp_param_spec_object_array (const gchar *name, array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_OBJECT_ARRAY, name, nick, blurb, flags); + g_return_val_if_fail (array_spec, NULL); + array_spec->object_type = object_type; return G_PARAM_SPEC (array_spec);