From: Olivier CrĂȘte Date: Sat, 19 Feb 2011 01:34:06 +0000 (-0500) Subject: GDBusProxy: Validate properties received from service if possible X-Git-Tag: 2.29.2~70 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa59fb9dd1a20004a5ba5f4d97c271eb5abe01e9;p=platform%2Fupstream%2Fglib.git GDBusProxy: Validate properties received from service if possible If the proxy has an GInterfaceInfo set, validate properties against it so the application doesn't have to do it. Signed-off-by: David Zeuthen --- diff --git a/gio/gdbusproxy.c b/gio/gdbusproxy.c index ac10aea..eecbaf6 100644 --- a/gio/gdbusproxy.c +++ b/gio/gdbusproxy.c @@ -768,6 +768,36 @@ on_signal_received (GDBusConnection *connection, /* ---------------------------------------------------------------------------------------------------- */ static void +insert_property_checked (GDBusProxy *proxy, + gchar *property_name, + GVariant *value) +{ + if (proxy->priv->expected_interface != NULL) + { + const GDBusPropertyInfo *info; + + info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name); + /* Ignore unknown properties */ + if (info == NULL) + goto invalid; + + /* Ignore properties with the wrong type */ + if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0) + goto invalid; + } + + g_hash_table_insert (proxy->priv->properties, + property_name, /* adopts string */ + value); /* adopts value */ + + return; + + invalid: + g_variant_unref (value); + g_free (property_name); +} + +static void on_properties_changed (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -815,9 +845,9 @@ on_properties_changed (GDBusConnection *connection, g_variant_iter_init (&iter, changed_properties); while (g_variant_iter_next (&iter, "{sv}", &key, &value)) { - g_hash_table_insert (proxy->priv->properties, - key, /* adopts string */ - value); /* adopts value */ + insert_property_checked (proxy, + key, /* adopts string */ + value); /* adopts value */ } for (n = 0; invalidated_properties[n] != NULL; n++) @@ -857,9 +887,9 @@ process_get_all_reply (GDBusProxy *proxy, g_variant_get (result, "(a{sv})", &iter); while (g_variant_iter_next (iter, "{sv}", &key, &value)) { - g_hash_table_insert (proxy->priv->properties, - key, /* adopts string */ - value); /* adopts value */ + insert_property_checked (proxy, + key, /* adopts string */ + value); /* adopts value */ } g_variant_iter_free (iter);