[glib] GDBus: Properly handle empty address strings



commit ef296440630ca01a8bc0a9dc58722bf1d6dc1ab7
Author: David Zeuthen <davidz redhat com>
Date:   Tue Jul 6 13:56:35 2010 -0400

    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>

 gio/gdbusaddress.c          |   13 ++++++++++++-
 gio/tests/gdbus-addresses.c |   14 ++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/gio/gdbusaddress.c b/gio/gdbusaddress.c
index 906e038..21c5203 100644
--- a/gio/gdbusaddress.c
+++ b/gio/gdbusaddress.c
@@ -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,
diff --git a/gio/tests/gdbus-addresses.c b/gio/tests/gdbus-addresses.c
index 568c775..dad986f 100644
--- a/gio/tests/gdbus-addresses.c
+++ b/gio/tests/gdbus-addresses.c
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]