From bd933b27a1f14f794b56630e9c8935f4d3b022b3 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Wed, 23 Feb 2011 12:02:37 -0600 Subject: [PATCH] libnm-glib: never propagate garbage values to async callbacks (bgo #642819) When a DBus error is received, the values of the other parameters may be undefined, but bindings will assume they're valid and fail. Capture this case and pass NULL to the callbacks. Also, allow passing NULL instead of a callback, for bindings that don't support the argument types. --- libnm-glib/nm-client.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c index e8a13d44a4..b63b818d05 100644 --- a/libnm-glib/nm-client.c +++ b/libnm-glib/nm-client.c @@ -1140,7 +1140,7 @@ activate_cb (DBusGProxy *proxy, ActivateDeviceInfo *info = (ActivateDeviceInfo *) user_data; if (info->act_fn) - info->act_fn (info->client, path, error, info->user_data); + info->act_fn (info->client, error ? NULL : path, error, info->user_data); else if (error) g_warning ("Device activation failed: (%d) %s", error->code, error->message); @@ -1155,8 +1155,8 @@ activate_cb (DBusGProxy *proxy, * @specific_object: (allow-none): the device specific object (currently * used only for activating wireless devices and should be the * #NMAccessPoint's path). - * @callback: (scope async): the function to call when the call is done - * @user_data: user data to pass to the callback function + * @callback: (scope async) (allow-none): the function to call when the call is done + * @user_data: (closure): user data to pass to the callback function * * Activates a connection with the given #NMDevice. **/ @@ -1196,9 +1196,13 @@ add_activate_cb (DBusGProxy *proxy, { ActivateDeviceInfo *info = (ActivateDeviceInfo *) user_data; - if (info->add_act_fn) - info->add_act_fn (info->client, connection_path, active_path, error, info->user_data); - else if (error) + if (info->add_act_fn) { + info->add_act_fn (info->client, + error ? NULL : connection_path, + error ? active_path : NULL, + error, + info->user_data); + } else if (error) g_warning ("Connection add and activate failed: (%d) %s", error->code, error->message); g_slice_free (ActivateDeviceInfo, info); @@ -1217,7 +1221,7 @@ add_activate_cb (DBusGProxy *proxy, * (ie, no specific object). For WiFi connections, pass the object path of a * specific AP from the card's scan list, which will be used to complete the * details of the newly added connection. - * @callback: (scope async): the function to call when the call is done + * @callback: (scope async) (allow-none): the function to call when the call is done * @user_data: (closure): user data to pass to the callback function * * Adds a new connection using the given details (if any) as a template