From 54c46d77bf92c9a69e829c2afce119cada536e69 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 27 Sep 2011 17:47:46 +0100 Subject: [PATCH 3/6] dbus_g_type_collection_get_fixed: check preconditions on the type and vtable Previously, if it wasn't a collection or didn't have the fixed_accessor, we'd just segfault. Not ideal. --- dbus/dbus-gtype-specialized.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-gtype-specialized.c b/dbus/dbus-gtype-specialized.c index 84efaf6..5eeb365 100644 --- a/dbus/dbus-gtype-specialized.c +++ b/dbus/dbus-gtype-specialized.c @@ -769,6 +769,7 @@ dbus_g_type_collection_get_fixed (GValue *value, guint *len_ret) { DBusGTypeSpecializedData *data; + DBusGTypeSpecializedCollectionVtable *vtable; GType gtype; dbus_g_type_specialized_init(); @@ -776,12 +777,17 @@ dbus_g_type_collection_get_fixed (GValue *value, g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), FALSE); gtype = G_VALUE_TYPE (value); + g_return_val_if_fail (dbus_g_type_is_collection (gtype), FALSE); + data = lookup_specialization_data (gtype); - g_return_val_if_fail (data != NULL, FALSE); + /* dbus_g_type_is_collection() already checked this */ + g_assert (data != NULL); - return ((DBusGTypeSpecializedCollectionVtable *) (data->klass->vtable))->fixed_accessor (gtype, - g_value_get_boxed (value), - data_ret, len_ret); + vtable = (DBusGTypeSpecializedCollectionVtable *) (data->klass->vtable); + g_return_val_if_fail (vtable->fixed_accessor != NULL, FALSE); + + return vtable->fixed_accessor (gtype, g_value_get_boxed (value), + data_ret, len_ret); } /** -- 1.7.6.3