GNOME Bugzilla – Bug 793400
g_application_id_is_valid() not strict enough
Last modified: 2018-03-13 12:52:40 UTC
GApplication uses g_application_id_is_valid() to check whether a given string is an allowable application ID. However, the dbus application impl uses the app ID as a *dbus name*, which has stricter requirements, leading to the situation that activating the application fails with "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Requested bus name "[name]" is not valid." even though the name *was* valid according to is_valid(). E.g.: g_application_id_is_valid("my.Terminal.0123") returns TRUE, while g_dbus_is_name("my.Terminal.0123") returns FALSE.
Indeed. It shouldn’t be an API break to make g_application_id_is_valid() be more strict, given that previously any invalid bus name would have caused a failure later on, when GApplication tried to register on the bus. We should apply all the rules from the D-Bus specification, and update the documentation to match — in particular, we should copy the advice about using underscores rather than hyphens: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus Would you be able to put together a patch?
Created attachment 369095 [details] [review] tests: Use modern test assertions in GApplication test This will make the assertion failure messages a little more useful, and prevent the assertions being compiled out with G_DISABLE_ASSERT. Introduces no functional changes. Signed-off-by: Philip Withnall <withnall@endlessm.com>
Created attachment 369096 [details] [review] gapplication: Tighten up application ID validation Tighten up the validation of application IDs so they are always exactly D-Bus well-known names. This is a slight change to the accepted format, but since anyone using the API with an application ID which was previously valid, but which was not a valid D-Bus well-known name, would have received an error from D-Bus when their application tried to register on the bus, I think this break is acceptable. It will affect any applications which have application IDs which are not valid D-Bus well-known names, and which use the G_APPLICATION_NON_UNIQUE flag. From a quick search in Debian Codesearch, no C applications use that flag. Update the documentation to use the rules from the D-Bus specification, including the latest advice discouraging use of hyphens: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus Update the tests: • Add the examples from the documentation to validate them. • Especially the venerable 7-zip.org example. • Move a couple of tests from expected-failure to expected-success: they are valid D-Bus well-known names even if they’re a bit weird. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This is too late to get into 2.56.0, but I’d like to get it into 2.56.1 to reduce the amount of time when we have all the reverse-DNS formats being different. Anyone going to review it?
Review of attachment 369095 [details] [review]: Okay
Review of attachment 369096 [details] [review]: Yep, this looks good.
Pushed to master. I will backport to glib-2-56 (for 2.56.1) shortly. Attachment 369095 [details] pushed as b046c5b - tests: Use modern test assertions in GApplication test Attachment 369096 [details] pushed as 7c1f38b - gapplication: Tighten up application ID validation
Backported to glib-2-56 too: 66948ae23 (HEAD -> glib-2-56, origin/glib-2-56) gapplication: Tighten up application ID validation d754e017e tests: Use modern test assertions in GApplication test