After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 720380 - Segfault when using GDBusMenuModel on a peer-to-peer connection
Segfault when using GDBusMenuModel on a peer-to-peer connection
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gapplication
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-12-13 09:46 UTC by Daiki Ueno
Modified: 2017-11-17 11:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tests/gmenumodel: Add a test case using peer-to-peer D-Bus connection (6.65 KB, patch)
2013-12-13 09:46 UTC, Daiki Ueno
none Details | Review
GDBusMenuModel: Allow NULL bus name for peer-to-peer connection (841 bytes, patch)
2013-12-13 09:46 UTC, Daiki Ueno
none Details | Review
GDBusMenuModel: Allow NULL bus name for peer-to-peer connection (846 bytes, patch)
2013-12-13 10:00 UTC, Daiki Ueno
reviewed Details | Review
tests/gmenumodel: Add test cases using peer-to-peer D-Bus connection (10.14 KB, patch)
2013-12-16 02:58 UTC, Daiki Ueno
committed Details | Review
GDBusMenuModel: Allow NULL bus name for peer-to-peer connection (1.64 KB, patch)
2013-12-16 02:58 UTC, Daiki Ueno
committed Details | Review
GDBusActionGroup: Allow NULL bus name for peer-to-peer connection (1.36 KB, patch)
2013-12-16 02:59 UTC, Daiki Ueno
committed Details | Review
GMenuExporter: Allow NULL bus name for peer-to-peer connection (3.48 KB, patch)
2013-12-16 03:01 UTC, Daiki Ueno
committed Details | Review

Description Daiki Ueno 2013-12-13 09:46:44 UTC
I'm trying to use GDBusMenuModel on a peer-to-peer D-Bus connection (with NULL bus name).  It works during the object is alive, but it segfaults when being unref'ed.  I'm attaching a test case which produces the following backtrace with the current code.

Program terminated with signal 11, Segmentation fault.
164	../sysdeps/x86_64/multiarch/strcmp-sse42.S: No such file or directory.
(gdb) bt
    b=0x7f8ff4001860) at gdbusmenumodel.c:200
    key=0x7f8ff4001860, hash_return=0x7fffb2cacde8) at ghash.c:386
    key=0x7f8ff4001860, notify=1) at ghash.c:1283
    key=0x7f8ff4001860) at ghash.c:1316
    at gdbusmenumodel.c:256
    at gdbusmenumodel.c:388
    at gdbusmenumodel.c:792

Note that we can't use non-NULL bus name here, since it hits an assertion in g_dbus_connection_signal_subscribe():

  g_return_val_if_fail (sender == NULL || (g_dbus_is_name (sender) && (connection->flags & G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION)), 0);
Comment 1 Daiki Ueno 2013-12-13 09:46:47 UTC
Created attachment 264126 [details] [review]
tests/gmenumodel: Add a test case using peer-to-peer D-Bus connection
Comment 2 Daiki Ueno 2013-12-13 09:46:51 UTC
Created attachment 264127 [details] [review]
GDBusMenuModel: Allow NULL bus name for peer-to-peer connection
Comment 3 Daiki Ueno 2013-12-13 09:51:18 UTC
Oops, lines beginning with '#' have been omitted when pasting.  The complete backtrace is:

Program terminated with signal 11, Segmentation fault.
  • #0 __strcmp_sse42
    at ../sysdeps/x86_64/multiarch/strcmp-sse42.S line 164
  • #0 __strcmp_sse42
    at ../sysdeps/x86_64/multiarch/strcmp-sse42.S line 164
  • #1 g_str_equal
    at ghash.c line 1764
  • #2 path_identifier_equal
    at gdbusmenumodel.c line 200
  • #3 g_hash_table_lookup_node
    at ghash.c line 386
  • #4 g_hash_table_remove_internal
    at ghash.c line 1283
  • #5 g_hash_table_remove
    at ghash.c line 1316
  • #6 g_dbus_menu_path_unref
    at gdbusmenumodel.c line 256
  • #7 g_dbus_menu_group_unref
    at gdbusmenumodel.c line 388
  • #8 g_dbus_menu_model_finalize
    at gdbusmenumodel.c line 792
  • #9 g_object_unref
    at gobject.c line 3171
  • #10 test_dbus_peer
    at gmenumodel.c line 1135

Comment 4 Daiki Ueno 2013-12-13 10:00:11 UTC
Created attachment 264129 [details] [review]
GDBusMenuModel: Allow NULL bus name for peer-to-peer connection
Comment 5 Allison Karlitskaya (desrt) 2013-12-13 14:30:01 UTC
Review of attachment 264129 [details] [review]:

Thanks for the patch (and the testcase to go with).

I feel like we should probably have some assertion check on entry to g_dbus_menu_model_get() that if the bus name is NULL then the connection is indeed peer-to-peer.  We then need improved docs, with an allow-none annotation.

You can find out if a connection is peer-to-peer by way of g_dbus_connection_get_unique_name().
Comment 6 Daiki Ueno 2013-12-16 02:58:14 UTC
Created attachment 264257 [details] [review]
tests/gmenumodel: Add test cases using peer-to-peer D-Bus connection

--
Run roundtrip and subscriptions tests on the peer-to-peer connection.
Comment 7 Daiki Ueno 2013-12-16 02:58:48 UTC
Created attachment 264258 [details] [review]
GDBusMenuModel: Allow NULL bus name for peer-to-peer connection

--
Added (allow-none) annotation and the assertion.
Comment 8 Daiki Ueno 2013-12-16 02:59:03 UTC
Created attachment 264259 [details] [review]
GDBusActionGroup: Allow NULL bus name for peer-to-peer connection
Comment 9 Daiki Ueno 2013-12-16 03:01:20 UTC
Created attachment 264260 [details] [review]
GMenuExporter: Allow NULL bus name for peer-to-peer connection

--
While adding more tests, I noticed that the exporter side needs similar treatment (sorry, it was not the case in my personal use-case, which was not fully peer-to-peer).
Comment 10 Matthias Clasen 2015-03-29 18:38:17 UTC
Ryan, should this finally land ?
Comment 11 Philip Withnall 2017-11-17 11:26:59 UTC
Review of attachment 264257 [details] [review]:

Nice.
Comment 12 Philip Withnall 2017-11-17 11:27:03 UTC
Review of attachment 264258 [details] [review]:

I’ll fix this annotation before pushing.

::: gio/gdbusmenumodel.c
@@ +852,3 @@
  * g_dbus_menu_model_get:
  * @connection: a #GDBusConnection
+ * @bus_name: (allow-none): the bus name which exports the menu model

(allow-none) is now (nullable).
Comment 13 Philip Withnall 2017-11-17 11:27:04 UTC
Review of attachment 264259 [details] [review]:

I’ll fix this annotation before pushing.

::: gio/gdbusactiongroup.c
@@ +470,3 @@
  * g_dbus_action_group_get:
  * @connection: A #GDBusConnection
+ * @bus_name: (allow-none): the bus name which exports the action

(allow-none) has since been replaced by (nullable).
Comment 14 Philip Withnall 2017-11-17 11:27:10 UTC
Review of attachment 264260 [details] [review]:

Looks good to me.
Comment 15 Philip Withnall 2017-11-17 11:29:51 UTC
Thanks for the patches (especially the unit tests); all pushed (with s/allow-none/nullable/). Sorry for the delay in reviewing them.

Attachment 264257 [details] pushed as c71098d - tests/gmenumodel: Add test cases using peer-to-peer D-Bus connection
Attachment 264258 [details] pushed as e8a09b3 - GDBusMenuModel: Allow NULL bus name for peer-to-peer connection
Attachment 264259 [details] pushed as d37af2b - GDBusActionGroup: Allow NULL bus name for peer-to-peer connection
Attachment 264260 [details] pushed as f29065c - GMenuExporter: Allow NULL bus name for peer-to-peer connection