[glib: 2/3] gdbusobjectmanagerserver: Disallow child objects at `/`




commit f0e0754f6290735b13c89bec515a89d7a141aa73
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Oct 1 10:43:14 2021 +0100

    gdbusobjectmanagerserver: Disallow child objects at `/`
    
    Previously, the code validated that child objects have a path with the
    object manager strictly as a prefix. That doesn’t work in the case where
    the object manager’s path is `/`. This case is not recommended, but is
    supported.
    
    If the object manager’s path is `/`, validate that child objects’ paths
    are not equal to it. If they are equal to it, warn the user rather than
    emitting a critical warning, since we can’t expect any users who’ve not
    been compliant with the spec to instantly rework their D-Bus APIs.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Fixes: #2500

 gio/gdbusobjectmanagerserver.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
---
diff --git a/gio/gdbusobjectmanagerserver.c b/gio/gdbusobjectmanagerserver.c
index 8e5c03e11..0b875be30 100644
--- a/gio/gdbusobjectmanagerserver.c
+++ b/gio/gdbusobjectmanagerserver.c
@@ -457,10 +457,31 @@ registration_data_free (RegistrationData *data)
   g_free (data);
 }
 
+/* Validate whether an object path is valid as a child of the manager. According
+ * to the specification:
+ * https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager
+ * this means that:
+ * > All returned object paths are children of the object path implementing this
+ * > interface, i.e. their object paths start with the ObjectManager's object
+ * > path plus '/'
+ *
+ * For example, if the manager is at `/org/gnome/Example`, children will be
+ * `/org/gnome/Example/(.+)`.
+ *
+ * It is permissible (but not encouraged) for the manager to be at `/`. If so,
+ * children will be `/(.+)`.
+ */
 static gboolean
 is_valid_child_object_path (GDBusObjectManagerServer *manager,
                             const gchar              *child_object_path)
 {
+  /* Historically GDBus accepted @child_object_paths at `/` if the @manager
+   * itself is also at `/". This is not spec-compliant, but making GDBus enforce
+   * the spec more strictly would be an incompatible change.
+   *
+   * See https://gitlab.gnome.org/GNOME/glib/-/issues/2500 */
+  g_warn_if_fail (!g_str_equal (child_object_path, manager->priv->object_path_ending_in_slash));
+
   return g_str_has_prefix (child_object_path, manager->priv->object_path_ending_in_slash);
 }
 


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