Commit Graph

8733 Commits

Author SHA1 Message Date
José Guilherme
efe2c24757 gdbus: factor out untranslatable parts of error messages 2024-06-13 18:30:58 +00:00
Biswapriyo Nath
7e69f88480 gcontenttype-win32: Copy documetation comment from gcontenttype
Fixes https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/509
2024-06-09 14:30:03 +00:00
Philip Withnall
601b8b45fb Merge branch '3184-socket-client-leak-with-unit-test' into 'main'
gsocketclient: Unit test for "Fix a leak of the task data on an error path"

Closes #3184

See merge request GNOME/glib!4104
2024-06-05 12:08:33 +00:00
Johan Sternerup
61e006e16c gsocketclient: Add unit test for leak of task data in error path
The unit test cover the error path that causes the leak described in
https://gitlab.gnome.org/GNOME/glib/-/issues/3184.
2024-06-05 12:54:15 +01:00
Philip Withnall
234871f1f9
gsocketclient: Fix a leak of the task data on an error path
Once the task is completed (and `g_task_return_*()` has been called),
the task is no longer needed. It would make more sense to unref it in
`complete_connection_with_error()`, where `g_task_return_*()` is called,
but that complicates other call sites significantly, so I didn’t do it.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3184
2024-06-05 12:54:05 +01:00
Bilal Elmoussaoui
b845d04918 gio/g-i: Mark Application:action-group property as deprecated
To avoid bindings making use of it
2024-06-04 14:38:02 +00:00
Maximiliano Sandoval
a7557f125e
gfile: Fix finish-func annotations
The finish-func should not contain the library_class prefix.
2024-06-01 16:49:34 +02:00
Philip Withnall
04de380f74 Merge branch 'wip/smcv/gdbusconn-comment' into 'main'
gdbusconnection: Fix a misleading comment

See merge request GNOME/glib!4063
2024-05-16 23:42:06 +00:00
Simon McVittie
434c105bbe gdbusconnection: Fix a misleading comment
While backporting CVE-2024-34397 fixes I noticed that this comment
claimed that the reference count is immutable after construction, which
is clearly not true. In fact the reference count is the only
mutable field.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:53:11 +01:00
Simon McVittie
510d0716be gdbus: Use symbolic constants for the most common D-Bus error names
To avoid adding a large block of macros to gdbusprivate.h, I've only
added a subset of the well-known error names. I chose to draw the
line by adding constants for the errors emitted via their string names
in GDBusConnection, but not for error names that are only mentioned
in `gdbuserror.c` or in tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
7c609f8142 gdbus: Use symbolic constants for interfaces from dbus-specification
Most D-Bus interfaces are domain-specific, but these interfaces from the
D-Bus Specification are intended to be commonly used in any context for
which they are found to be appropriate.

Most of these use `gdbusprivate.h`. One exception is that
`gio/tests/gdbus-example-*` redefine the constants locally: due to these
files' dual role as part of the unit tests and as sample code, it seems
desirable to ensure that they can still be compiled outside GLib.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
b4f8d4a5d5 gdbus: Use symbolic constants for the reserved Local path and interface
These are reserved by the D-Bus Specification.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
7401577074 gdbus: Move protocol constants from gdbusdaemon into gdbusprivate.h
These well-known flags and replies are part of the D-Bus Specification,
and also exist with the same names in libdbus header files.
Moving them into a private header means that unit tests like
gdbus-proxy-threads and gdbus-subscribe don't have to reinvent them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
b0e8612a3b gdbusdaemon: Use shared constants for message bus name, path, interface
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
131a061aca gdbus: Use symbolic constants for various references to the message bus
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
19223803f5 gdbus: Use symbolic constants to subscribe to message bus signals
Unlike the various functions to call D-Bus methods, these sort their
arguments in a non-obvious order (bus name, interface, signal, path),
presumably aiming to sort the most-likely-to-be-used arguments first.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
fe14968c0d gdbus: Use symbolic constants to call message bus methods
These function arguments are arranged in the obvious order from
conceptually largest to smallest: (bus name, path, interface, method).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:22 +01:00
Simon McVittie
2151a82007 gdbus tests: Fix a typo
This test was subscribing to the NameOwnerChanged signal with an
incorrect object path, so the callback would never be called. In this
particular case it doesn't actually matter, because the callback does
nothing anyway (the purpose of this particular test was to test that
the user-data is freed on unsubscription).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:22 +01:00
Michael Catanzaro
b9490a499a Merge branch '3366-menu-exporter-error-handling' into 'main'
gmenuexporter: Fix a NULL pointer dereference on an error handling path

Closes #3366

See merge request GNOME/glib!4073
2024-05-15 14:55:18 +00:00
Philip Withnall
7a7137838e
gactiongroupexporter: Fix memory problems on an error handling path
Almost identically to the previous commit, fix a similar latent bug in
`g_dbus_connection_export_action_group()`, which was not ready to handle
the fledgling `GActionGroupExporter` being freed early on an error
handling path.

See the previous commit message for details of the approach.

This includes a unit test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3366
2024-05-15 14:00:09 +01:00
Philip Withnall
df2c5d925a
gmenuexporter: Fix a NULL pointer dereference on an error handling path
This latent bug wasn’t triggered until commit 3f30ec86c (or its
cherry-pick onto `glib-2-80`, 747e3af99, which was first released in
2.80.1).

That change means that `g_menu_exporter_free()` is now called on the
registration failure path by `g_dbus_connection_register_object()`
before it returns. The caller then tries to call `g_slice_free()` on the
exporter again. The call to `g_menu_exporter_free()` tries to
dereference/free members of the exporter which it expects to be
initialised — but because this is happening in an error handling path,
they are not initialised.

If it were to get any further, the `g_slice_free()` would then be a
double-free on the exporter allocation.

Fix that by making `g_menu_exporter_free()` robust to some of the
exporter members being `NULL`, and moving some of the initialisation
code higher in `g_dbus_connection_export_menu_model()`, and removing the
duplicate free code on the error handling path.

This includes a unit test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3366
2024-05-15 12:52:38 +01:00
Dr. David Alan Gilbert
1bc83f9495 Remove unused structs
gio/glocalfileinfo.c has a struct 'ThumbMD5Context'
that's been unused since
commit d013d46b98 ("Replace the copy-and-paste MD5 digest generation
with GChecksum.")
Remove it.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
2024-05-15 12:10:25 +01:00
Marco Trevisan (Treviño)
486ad65535 gio/tests: Enable gsocketclient-slow under address santizer
The test can run properly, even though we won't do the right checks on
the preloaded library
2024-05-10 02:44:07 +02:00
Marco Trevisan (Treviño)
0eb6c85606 build: Define glib_sanitizers variable to easily get the sanitizers in use
It's an array containing the list of sanitizers in use, normally it
contains a value, but in some cases may have more than one (e.g.
'address' and 'undefined').

And so use it to avoid repeated checks
2024-05-10 02:15:52 +02:00
Marco Trevisan (Treviño)
84259c46fa gio/tests/subprocess: Skip the trapped test under ASAN since it uses ptrace
And as the sanitizer tells us, it doesn't support it
2024-05-09 17:51:10 +02:00
Marco Trevisan (Treviño)
5c84823342 gio/tests/gsettings: Cleanup allocated new locales 2024-05-09 17:25:56 +02:00
Marco Trevisan (Treviño)
ddfc8e2918 glocalfile: Trash, free values when done avoiding leaks on early returns
In glocalfile we're allocating some temporary strings but we don't free
them on early returns, so free them once done and unset the variables
to prevent them being used incorrectly.
2024-05-09 17:25:56 +02:00
Marco Trevisan (Treviño)
365411ea32 gio/tests/cancellable: Explain failure on GCancellableSource tests on valgrind
It looks like that finally also valgrind notices the same leaks as
address sanitizer does. It does it more randomly but it still happens,
so better to inform about until #2309 is resolved.
2024-05-09 17:25:56 +02:00
Philip Withnall
86dd02f487 Merge branch 'convert-bytes' into 'main'
Add g_converter_convert_bytes

See merge request GNOME/glib!4035
2024-05-09 15:03:56 +00:00
Matthias Clasen
0855968727 Add g_converter_convert_bytes
Add a utility api to apply a GConverter to data in memory.

Test included.
2024-05-09 15:03:55 +00:00
Marco Trevisan (Treviño)
8966099e9b gdbusmessage: Clean the cached arg0 when setting the message body
We're now caching arg0 but such value is not cleared when a new body is
set as it's in the connection filter test cases where we've a leak as
highlighted by both valgrind and leak sanitizer
2024-05-08 22:56:24 +02:00
Simon McVittie
7d65f6c5a2 gdbusconnection: Allow name owners to have the syntax of a well-known name
In a D-Bus-Specification-compliant message bus, the owner of a well-known
name is a unique name. However, ibus has its own small implementation
of a message bus (src/ibusbus.c) in which org.freedesktop.IBus is
special-cased to also have itself as its owner (like org.freedesktop.DBus
on a standard message bus), and connects to that bus with the
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION flag. The ability to do
this regressed when CVE-2024-34397 was fixed.

Relax the checks to allow the owner of a well-known name to be any valid
D-Bus name, even if it is not syntactically a unique name.

Fixes: 683b14b9 "gdbus: Track name owners for signal subscriptions"
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3353
Bug-Debian: https://bugs.debian.org/1070730
Bug-Debian: https://bugs.debian.org/1070736
Bug-Debian: https://bugs.debian.org/1070743
Bug-Debian: https://bugs.debian.org/1070745
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-05-08 14:46:08 +00:00
Marco Trevisan
4623c960c1 Merge branch 'fix-gdbus-connection-test' into 'main'
gdbusconnection: Fix test signal subscription ordering

See merge request GNOME/glib!4051
2024-05-07 23:38:31 +00:00
Ray Strode
47866d252f gdbusconnection: Fix test signal subscription ordering
The test case assumes signals will dispatched in a different order than
they're subscribed. In fact, signals can be dispatched in any order,
and are often dispatched in order.

This commit reorders the subscriptions so they're in order, which is
more logical, and also changes the code to only exit the event loops
when there are no pending handlers ready to dispatch.
2024-05-07 18:45:45 -04:00
Philip Withnall
b9e655b4d4
gapplication: Fix a small leak on an error handling path
This was highlighted (but not introduced) by
0144feb41f. Previously the test coverage
didn’t cover this branch, I think.

`iter` was leaked, and at this point `parameter` had never been set, so
clearing it was unnecessary.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3349
2024-05-07 17:04:28 +01:00
Philip Withnall
d22c4574cd Merge branch '2.82-bus-name-owners' into 'main'
gdbusconnection: Don't deliver signals if the sender doesn't match

Closes #3268

See merge request GNOME/glib!4038
2024-05-07 14:30:22 +00:00
Simon McVittie
7b15b1db40 gdbus-proxy test: Wait before asserting name owner has gone away
GDBusConnection sends each signal to recipients in a separate idle
callback, and there's no particular guarantee about the order in which
they're scheduled or dispatched. For the NameOwnerChanged signal that
reports the name becoming unowned, it's possible that g_bus_watch_name()
gets its idle callback called before the GDBusProxy:g-name-owner
machinery has updated the name owner, in which case the assertion
will fail.

Fixing GNOME/glib#3268 introduced a new subscription to NameOwnerChanged
which can alter the order of delivery, particularly in the case where
G_DBUS_PROXY_FLAGS_NO_MATCH_RULE was used (as tested in
/gdbus/proxy/no-match-rule). The resulting test failure is intermittent,
but reliably appears within 100 repetitions of that test.

Fixes: 511c5f5b "tests: Wait for gdbus-testserver to die when killing it"
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-05-07 14:40:52 +01:00
Matthias Clasen
64cd43029e Revert "Add GBase64Encoder and Decoder"
This reverts commit b2c11516e2.
2024-05-05 14:58:43 -04:00
Matthias Clasen
b2c11516e2 Add GBase64Encoder and Decoder
These are GConverter implementations that convert to/from
base64 encoding.

Originally written by Christian Persch.

Fixes: #305
2024-05-05 14:53:14 -04:00
Simon McVittie
43c5af517c gdocumentportal: Treat more error codes as a permissions error
If the file to be added is on a read-only filesystem, opening read/write
will fail with EROFS. In this case we should fall back to opening it
read-only, the same way we already do if write access is forbidden by
DAC or MAC.

An easy way to reproduce this test failure is to build and test GLib
in a podman container, with its source code read-only and its build
directory read/write:

    podman run --rm -it \
    -v $(pwd):$(pwd):ro \
    -v $(pwd)/_build:$(pwd)/_build:rw \
    -w $(pwd) ...

Before this commit, the dbus-appinfo test would fail, because opening
${srcdir}/gio/tests/org.gtk.test.dbusappinfo.flatpak.desktop read/write
would fail with EROFS.

For completeness, give similar handling to the other error codes
documented in Linux open(2) that might succeed if re-attempted using
read-only access: according to that documentation, we could get EPERM
if opening read/write is prevented by fcntl F_ADD_SEALS, or ETXTBSY
if the file is an executable that is currently being run.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 18:34:04 +01:00
Simon McVittie
8c533510ee gdocumentportal: Factor out opening_ro_might_succeed()
No functional change.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 18:33:37 +01:00
Ray Strode
c7caf98646 Merge branch 'track-bus-name-owners-for-signal-subscriptions' into 'main'
Track bus name owners for signal subscriptions

See merge request GNOME/Security/glib!1
2024-05-01 13:34:40 +00:00
Simon McVittie
96e3190aef tests: Ensure that unsubscribing with GetNameOwner in-flight doesn't crash
This was a bug that existed during development of this branch; make sure
it doesn't come back.

This test fails with a use-after-free and crash if we comment out the
part of name_watcher_unref_watched_name() that removes the name watcher
from `map_method_serial_to_name_watcher`.

It would also fail with an assertion failure if we asserted in
name_watcher_unref_watched_name() that get_name_owner_serial == 0
(i.e. that GetNameOwner is not in-flight at destruction).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
f6d1b5471a tests: Add a test for signal filtering by well-known name
The vulnerability reported as GNOME/glib#3268 can be characterized
as: these signals from an attacker should not be delivered to either
the GDBusConnection or the GDBusProxy, but in fact they are (in at
least some scenarios).

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/3268
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
fc0ee92072 tests: Add a test for matching by two well-known names
The expected result is that because TEST_CONN_SERVICE owns
ALREADY_OWNED_NAME but not (yet) OWNED_LATER_NAME, the signal will be
delivered to the subscriber for the former but not the latter.
Before #3268 was fixed, it was incorrectly delivered to both.

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/3268 (partially)
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
d4b6537651 gdbusconnection: Don't deliver signals if the sender doesn't match
Otherwise a malicious connection on a shared bus, especially the system
bus, could trick GDBus clients into processing signals sent by the
malicious connection as though they had come from the real owner of a
well-known service name.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3268
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
683b14b981 gdbus: Track name owners for signal subscriptions
We will use this in a subsequent commit to prevent signals from an
impostor from being delivered to a subscriber.

To avoid message reordering leading to misleading situations, this does
not use the existing mechanism for watching bus name ownership, which
delivers the ownership changes to other main-contexts. Instead, it all
happens on the single thread used by the GDBusWorker, so the order in
which messages are received is the order in which they are processed.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:27:24 +01:00
Philip Withnall
fd93e12669
gdbusconnection: Fix a crash on arg0 matching
If a connection has two signal subscriptions active for the same signal,
one with arg0 matching and one without, a signal which doesn’t contain
an arg0 value (i.e. `g_dbus_message_get_arg0()` returns `NULL`) will
cause `NULL` to be passed to `strcmp()` when checking for a match
against the signal subscription which *has* arg0 matching, causing a
crash.

Fix that by adding the obvious `NULL` check, and add a unit test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3342
2024-04-30 18:33:57 +01:00
Julian Sparber
0144feb41f GApplication: Allow multiple parameters for D-Bus activation
D-Bus Activation allows passing an array of parameters. Allow apps to
export actions that accept tuples to match the number of elements in the
parameters so the full potential of the D-Bus interface can be used.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/3333
2024-04-29 16:30:36 +02:00
Philip Withnall
d2f5cd4153
tests: Fix a -Wmaybe-uninitialized warning in gdbus-serialization test
It’s a false positive, but easy enough to squash.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-25 23:57:55 +01:00