Shouldn't gerror_to_dbus_error_message check for both DBUS_GERROR and DBUS_GERROR_REMOTE_EXCEPTION?
Marcel Tünnissen
marcel.tunnissen at axis.com
Fri Sep 6 07:14:44 PDT 2013
Hi,
I am looking at a crash that occurs sometimes in our code.
It is caused by a call to dbus_message_new_error from
gerror_to_dbus_error_message
In the call the second parameter error_name becomes NULL.
This is obtained through a call to dbus_g_error_get_name
Apparently the function requires both DBUS_GERROR and
DBUS_GERROR_REMOTE_EXCEPTION.
As a reference:
/**
* dbus_g_error_get_name:
* @error: the #GError given from the remote method
* @name: the D-BUS error name
* @msg: the D-BUS error detailed message
*
* This function may only be invoked on a #GError returned from an
* invocation of a remote method, e.g. via dbus_g_proxy_end_call.
* Moreover, you must ensure that the error's domain is #DBUS_GERROR,
* and the code is #DBUS_GERROR_REMOTE_EXCEPTION.
*
* Returns: the D-BUS name for a remote exception.
*/
const char *
dbus_g_error_get_name (GError *error)
{
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail (error->domain == DBUS_GERROR, NULL);
g_return_val_if_fail (error->code == DBUS_GERROR_REMOTE_EXCEPTION, NULL);
return error->message + strlen (error->message) + 1;
}
However the calling function only checks for DBUS_GERROR.
The call to dbus_g_error_get_name from
gerror_to_dbus_error_message
looks like:
DBusMessage *
gerror_to_dbus_error_message (const DBusGObjectInfo *object_info,
DBusMessage *message,
GError *error)
{
DBusMessage *reply;
if (!error)
{
char *error_msg;
error_msg = g_strdup_printf ("Method invoked for %s returned FALSE
but did not set error", dbus_message_get_member (message));
reply = dbus_message_new_error (message,
"org.freedesktop.DBus.GLib.ErrorError", error_msg);
g_free (error_msg);
}
else
{
if (error->domain == DBUS_GERROR)
reply = dbus_message_new_error (message,
dbus_g_error_get_name (error),
error->message);
else
{
char *error_name;
error_name = gerror_domaincode_to_dbus_error_name (object_info,
dbus_message_get_interface (message),
error->domain,
error->code);
reply = dbus_message_new_error (message, error_name,
error->message);
g_free (error_name);
}
}
return reply;
}
It seems to me that the single check for error->domain == DBUS_GERROR
isn't sufficient.
Should this check for error->code == DBUS_GERROR_REMOTE_EXCEPTION as well?
So that gerror_domaincode_to_dbus_error_name is called to retrieve the
error_name?
Best Regards
Marcel Tünnissen
--
Marcel Tünnissen,
Axis Communications AB
Emdalavägen 14, SE-223 69 LUND, SWEDEN
Phone: +46 (0)46 272 2448
+46 (0)729 890 369
Email: marcel.tunnissen at axis.com,
WWW: http://www.axis.com
More information about the dbus
mailing list