]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
bus_driver_get_owner_of_name: factor out from bus_driver_get_conn_helper
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 26 Jan 2015 20:06:04 +0000 (20:06 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 5 Feb 2015 14:54:28 +0000 (14:54 +0000)
We need this, or something equivalent, to address CVE-2015-0245 via
code changes.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88811
Reviewed-by: Alban Crequy
Reviewed-by: David King
Reviewed-by: Philip Withnall
bus/driver.c

index f5d3ebe2128419408b03b89c6e1aa24ab233835b..9551f3d4068bc06866cea94a1cbe931b89af91bd 100644 (file)
 #include <dbus/dbus-marshal-recursive.h>
 #include <string.h>
 
+static DBusConnection *
+bus_driver_get_owner_of_name (DBusConnection *connection,
+                              const char     *name)
+{
+  BusRegistry *registry;
+  BusService *serv;
+  DBusString str;
+
+  registry = bus_connection_get_registry (connection);
+  _dbus_string_init_const (&str, name);
+  serv = bus_registry_lookup (registry, &str);
+
+  if (serv == NULL)
+    return NULL;
+
+  return bus_service_get_primary_owners_connection (serv);
+}
+
 static DBusConnection *
 bus_driver_get_conn_helper (DBusConnection  *connection,
                             DBusMessage     *message,
@@ -47,11 +65,8 @@ bus_driver_get_conn_helper (DBusConnection  *connection,
                             const char     **name_p,
                             DBusError       *error)
 {
-  const char *name;
-  BusRegistry *registry;
-  BusService *serv;
-  DBusString str;
   DBusConnection *conn;
+  const char *name;
 
   if (!dbus_message_get_args (message, error,
                               DBUS_TYPE_STRING, &name,
@@ -61,11 +76,9 @@ bus_driver_get_conn_helper (DBusConnection  *connection,
   _dbus_assert (name != NULL);
   _dbus_verbose ("asked for %s of connection %s\n", what_we_want, name);
 
-  registry = bus_connection_get_registry (connection);
-  _dbus_string_init_const (&str, name);
-  serv = bus_registry_lookup (registry, &str);
+  conn = bus_driver_get_owner_of_name (connection, name);
 
-  if (serv == NULL)
+  if (conn == NULL)
     {
       dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER,
                       "Could not get %s of name '%s': no such name",
@@ -73,9 +86,6 @@ bus_driver_get_conn_helper (DBusConnection  *connection,
       return NULL;
     }
 
-  conn = bus_service_get_primary_owners_connection (serv);
-  _dbus_assert (conn != NULL);
-
   if (name_p != NULL)
     *name_p = name;