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 793400 - g_application_id_is_valid() not strict enough
g_application_id_is_valid() not strict enough
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gapplication
unspecified
Other Linux
: Normal normal
: 2.56
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-02-12 18:48 UTC by Christian Persch
Modified: 2018-03-13 12:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tests: Use modern test assertions in GApplication test (3.22 KB, patch)
2018-02-28 12:52 UTC, Philip Withnall
committed Details | Review
gapplication: Tighten up application ID validation (8.05 KB, patch)
2018-02-28 12:52 UTC, Philip Withnall
committed Details | Review

Description Christian Persch 2018-02-12 18:48:15 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.
Comment 1 Philip Withnall 2018-02-13 14:05:04 UTC
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?
Comment 2 Philip Withnall 2018-02-28 12:52:19 UTC
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>
Comment 3 Philip Withnall 2018-02-28 12:52:25 UTC
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>
Comment 4 Philip Withnall 2018-03-05 13:17:02 UTC
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?
Comment 5 Emmanuele Bassi (:ebassi) 2018-03-13 11:57:58 UTC
Review of attachment 369095 [details] [review]:

Okay
Comment 6 Emmanuele Bassi (:ebassi) 2018-03-13 11:59:47 UTC
Review of attachment 369096 [details] [review]:

Yep, this looks good.
Comment 7 Philip Withnall 2018-03-13 12:46:37 UTC
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
Comment 8 Philip Withnall 2018-03-13 12:52:40 UTC
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