fix for incorrect session bus descriptor lookup 46/177346/1
authorAleksy Barcz <a.barcz@partner.samsung.com>
Tue, 24 Apr 2018 11:08:57 +0000 (13:08 +0200)
committerAleksy Barcz <a.barcz@partner.samsung.com>
Fri, 27 Apr 2018 08:16:06 +0000 (10:16 +0200)
Bugfix for error handling on dbus-daemon systems.
If get_session_address_platform_specific failed, both error and return value would be set,
resulting in subsequent error overwrite and a glib warning.

Change-Id: Ic0e42ed6868fc9dd71965ce23e68c8dbc8596ff5

gio/gdbusaddress.c

index 69d233f..0854788 100644 (file)
@@ -1086,6 +1086,30 @@ out:
 #endif
 }
 
+static gchar *
+get_session_address_kdbus (void)
+{
+#ifdef G_OS_UNIX
+  gchar *ret = NULL;
+  gchar *bus;
+  GStatBuf buf;
+
+  bus = g_strdup_printf ("/sys/fs/kdbus/%d-user/bus", getuid());
+
+  /* if ENOENT, EPERM, etc., quietly don't use it */
+  if (g_stat (bus, &buf) < 0)
+    goto out;
+
+  ret = g_strconcat ("kernel:path=", bus, NULL);
+
+out:
+  g_free (bus);
+  return ret;
+#else
+  return NULL;
+#endif
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 #ifdef G_OS_UNIX
@@ -1667,10 +1691,11 @@ g_dbus_address_get_for_bus_sync (GBusType       bus_type,
       ret = g_strdup (g_getenv ("DBUS_SESSION_BUS_ADDRESS"));
       if (ret == NULL)
         {
-          gchar *s;
-          s = get_session_address_platform_specific (&local_error);
-          ret = g_strdup_printf ("kernel:path=/sys/fs/kdbus/%d-user/bus;%s", getuid(), s);
-          g_free(s);
+          ret = get_session_address_kdbus ();
+          if (ret == NULL)
+            ret = get_session_address_platform_specific (&local_error);
+          if (ret == NULL)
+            goto out;
         }
       break;