GDBus: Properly handle empty address strings

Changes this error

 DBUS_SESSION_BUS_ADDRESS= \
 gdbus introspect --session \
                  --dest org.freedesktop.DBus \
                  --object-path /org/freedesktop/DBus
 **
 GLib-GIO:ERROR:gdbusaddress.c:913:g_dbus_address_get_stream_sync: assertion failed: (last_error != NULL)
 Aborted (core dumped)

to

 DBUS_SESSION_BUS_ADDRESS= \
 gdbus introspect --session \
                  --dest org.freedesktop.DBus \
                  --object-path /org/freedesktop/DBus
 Error connecting: The given address is empty

which is much more preferable.

Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
David Zeuthen 2010-07-06 13:56:35 -04:00
parent f0b6cbb139
commit ef29644063
2 changed files with 26 additions and 1 deletions

View File

@ -83,6 +83,9 @@ g_dbus_is_address (const gchar *string)
g_return_val_if_fail (string != NULL, FALSE);
a = g_strsplit (string, ";", 0);
if (a[0] == NULL)
goto out;
for (n = 0; a[n] != NULL; n++)
{
if (!_g_dbus_address_parse_entry (a[n],
@ -879,11 +882,19 @@ g_dbus_address_get_stream_sync (const gchar *address,
last_error = NULL;
addr_array = g_strsplit (address, ";", 0);
last_error = NULL;
if (addr_array[0] == NULL)
{
last_error = g_error_new_literal (G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("The given address is empty"));
goto out;
}
for (n = 0; addr_array != NULL && addr_array[n] != NULL; n++)
{
const gchar *addr = addr_array[n];
GError *this_error;
this_error = NULL;
ret = g_dbus_address_try_connect_one (addr,
out_guid,

View File

@ -28,6 +28,19 @@
/* ---------------------------------------------------------------------------------------------------- */
static void
test_empty_address (void)
{
GError *error;
error = NULL;
g_dbus_address_get_stream_sync ("",
NULL,
NULL,
&error);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
g_error_free (error);
}
#ifdef G_OS_UNIX
static void
test_unix_address (void)
@ -68,6 +81,7 @@ main (int argc,
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gdbus/empty-address", test_empty_address);
#ifdef G_OS_UNIX
g_test_add_func ("/gdbus/unix-address", test_unix_address);
#endif