Bug 23297 - should allow duplicate object registrations
Summary: should allow duplicate object registrations
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: GLib (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Will Thompson
QA Contact: John (J5) Palmieri
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2009-08-13 16:19 UTC by Colin Walters
Modified: 2009-11-25 06:56 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Support duplicate object registrations (13.43 KB, patch)
2009-08-19 13:13 UTC, Colin Walters
Details | Splinter Review
this time without g_printerr (12.55 KB, patch)
2009-08-19 13:17 UTC, Colin Walters
Details | Splinter Review
Support duplicate object registrations (12.56 KB, patch)
2009-09-12 04:02 UTC, Will Thompson
Details | Splinter Review
Only re-set registration list if it's non-empty (988 bytes, patch)
2009-09-12 04:02 UTC, Will Thompson
Details | Splinter Review
Copy object registration list when unregistering. (1.49 KB, patch)
2009-09-12 04:02 UTC, Will Thompson
Details | Splinter Review

Description Colin Walters 2009-08-13 16:19:38 UTC
For backwards compat, PolicyKit does:

         dbus_g_connection_register_g_object (manager->priv->session_bus_connection, 
                                              "/org/gnome/PolicyKit/Manager", 
                                              G_OBJECT (manager));
         dbus_g_connection_register_g_object (manager->priv->session_bus_connection, 
                                              "/", 
                                              G_OBJECT (manager));

This broke with 0.82, commit 6de1441865da281.  We should probably allow duplicate registrations for dispatch purposes.  When mapping back from object->path, simply have first one wins behavior.
Comment 1 Colin Walters 2009-08-19 13:13:46 UTC
Created attachment 28791 [details] [review]
Support duplicate object registrations
Comment 2 Colin Walters 2009-08-19 13:17:01 UTC
Created attachment 28792 [details] [review]
this time without g_printerr
Comment 3 Dan Williams 2009-08-21 12:23:26 UTC
Hmm, not quite...  quick testing shows that:

[dcbw@localhost devel]$ dbus-send --session --print-reply --dest=org.freedesktop.PolicyKit.AuthenticationAgent /org/freedesktop/PolicyKit/Manager org.freedesktop.PolicyKit.AuthenticationAgent.ObtainAuthorization string:org.freedesktop.network-manager-settings.system.modify uint32:0 uint32:123
Error org.freedesktop.DBus.Error.UnknownMethod: Method "ObtainAuthorization" with signature "suu" on interface "org.freedesktop.PolicyKit.AuthenticationAgent" doesn't exist

[dcbw@localhost devel]$ dbus-send --session --print-reply --dest=org.freedesktop.PolicyKit.AuthenticationAgent / org.freedesktop.PolicyKit.AuthenticationAgent.ObtainAuthorization string:org.freedesktop.network-manager-settings.system.modify uint32:0 uint32:123
method return sender=:1.251 -> dest=:1.252 reply_serial=2
   boolean true

whereas I'd expect both of these commands (which differ only by object path) to return the exact same result.
Comment 4 Dan Williams 2009-08-21 12:39:07 UTC
Introspect also doesn't work for the first registration:

[dcbw@localhost dbus]$ dbus-send --session --print-reply --dest=org.freedesktop.PolicyKit.AuthenticationAgent /org/freedesktop/PolicyKit/Manager org.freedesktop.DBus.Introspectable.Introspect 
method return sender=:1.268 -> dest=:1.270 reply_serial=2
   string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
</node>
"

while using "/" as the path does.  Trying to track this down.
Comment 5 Dan Williams 2009-08-21 15:11:33 UTC
Ignore all that; works fine.  I had the object path wrong.
Comment 6 Will Thompson 2009-09-02 12:38:39 UTC
Shouldn't object_registration_free() only re-set_data on the object if the list is non-NULL? (Obviously this is trivia.)

I think that when _unregister_g_object() calls _unregister_object_path(), the latter causes object_registration_free() to be called, which deletes the link from 'registrations' that 'iter' is currently pointing at. Then 'iter = iter->next' runs, and is dereferencing freed memory. I think advancing 'iter' before calling dbus_connection_unregister_object_path() would work, but wouldn't be obviously correct; maybe copy the list, iterate and free the copy, and then assert that g_object_get_data (object, "dbus_glib_object_registrations"); returns NULL? (It took me a couple of minutes to figure out how the ObjectRegistrations were being freed, so it could do with a comment either way.)

(The patch adds some trailing whitespace and tabs even as it diligently removes other trailing whitespace and tabs. :))
Comment 7 Will Thompson 2009-09-02 12:39:07 UTC
(Stealing the bug from Simon.)
Comment 8 Michael Biebl 2009-09-11 16:50:08 UTC
Is there progress on this bug, is the patch the correct fix or does it need further review?
Comment 9 Will Thompson 2009-09-12 03:21:24 UTC
Well, I'm pretty sure it uses freed memory; I'll knock up a couple more patches fixing my review comments.
Comment 10 Will Thompson 2009-09-12 04:02:18 UTC
Created attachment 29445 [details] [review]
Support duplicate object registrations

Before commit e869fda4, we semi-supported registering the
same object multiple times.  We'd accept messages for both paths,
however when signals were emitted, they'd both use the first object
path.

That commit simply disallowed multiple registrations, which broke
backwards compatibility with some projects like PolicyKit which
had the same object registered with different paths.

With this commit, explicitly allow and support multiple registrations.
The primary change is that signals are now emitted once for each
registration path of an object, using the correct path.
Comment 11 Will Thompson 2009-09-12 04:02:21 UTC
Created attachment 29446 [details] [review]
Only re-set registration list if it's non-empty
Comment 12 Will Thompson 2009-09-12 04:02:24 UTC
Created attachment 29447 [details] [review]
Copy object registration list when unregistering.

Since the list of registrations on the object is modified when each path
is removed, iterating it directly is wrong: after the first pass of the
loop, 'iter' would point to a link which has been freed.
Comment 13 Will Thompson 2009-09-12 04:03:00 UTC
Comment on attachment 28792 [details] [review]
this time without g_printerr

I've attached an updated version of this patch which does not add trailing whitespace.
Comment 14 Will Thompson 2009-09-12 04:04:09 UTC
The attached patches (also at <http://git.collabora.co.uk/?p=user/wjt/dbus-glib-wjt.git;a=shortlog;h=refs/heads/duplicate-registrations>) fix the problems I found while reviewing. I think they're good to go; could someone (Colin?) review my fixes and commit them?
Comment 15 Simon McVittie 2009-09-29 06:16:46 UTC
Reviewing...
Comment 16 Simon McVittie 2009-09-29 06:25:02 UTC
Looks good to me with Will's changes (i.e. commit 90e2199a), so I pushed it. Fixed in git for 0.84.
Comment 17 Jürg Billeter 2009-11-23 03:22:45 UTC
Where did you push these changes? I don't see them on http://cgit.freedesktop.org/dbus/dbus-glib/
Comment 18 Simon McVittie 2009-11-25 06:56:13 UTC
Well spotted. *Really* fixed in git now :-)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.