mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-19 23:28:54 +02:00
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:
@@ -83,6 +83,9 @@ g_dbus_is_address (const gchar *string)
|
|||||||
g_return_val_if_fail (string != NULL, FALSE);
|
g_return_val_if_fail (string != NULL, FALSE);
|
||||||
|
|
||||||
a = g_strsplit (string, ";", 0);
|
a = g_strsplit (string, ";", 0);
|
||||||
|
if (a[0] == NULL)
|
||||||
|
goto out;
|
||||||
|
|
||||||
for (n = 0; a[n] != NULL; n++)
|
for (n = 0; a[n] != NULL; n++)
|
||||||
{
|
{
|
||||||
if (!_g_dbus_address_parse_entry (a[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;
|
last_error = NULL;
|
||||||
|
|
||||||
addr_array = g_strsplit (address, ";", 0);
|
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++)
|
for (n = 0; addr_array != NULL && addr_array[n] != NULL; n++)
|
||||||
{
|
{
|
||||||
const gchar *addr = addr_array[n];
|
const gchar *addr = addr_array[n];
|
||||||
GError *this_error;
|
GError *this_error;
|
||||||
|
|
||||||
this_error = NULL;
|
this_error = NULL;
|
||||||
ret = g_dbus_address_try_connect_one (addr,
|
ret = g_dbus_address_try_connect_one (addr,
|
||||||
out_guid,
|
out_guid,
|
||||||
|
@@ -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
|
#ifdef G_OS_UNIX
|
||||||
static void
|
static void
|
||||||
test_unix_address (void)
|
test_unix_address (void)
|
||||||
@@ -68,6 +81,7 @@ main (int argc,
|
|||||||
g_type_init ();
|
g_type_init ();
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/gdbus/empty-address", test_empty_address);
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
g_test_add_func ("/gdbus/unix-address", test_unix_address);
|
g_test_add_func ("/gdbus/unix-address", test_unix_address);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user