Commit Graph

30173 Commits

Author SHA1 Message Date
Marco Trevisan (Treviño)
a5ec1dd612
glib/tests/constructor: Add test dependency on constructor_lib
Otherwise we may build the test but not its dependent library
2024-05-09 15:36:43 +01:00
Simon McVittie
cd65260dae Merge branch 'backport-4057-arg0-leak-fix-glib-2-80' into 'glib-2-80'
Backport !4057 “gdbusmessage: Clean the cached arg0 when setting the message body” to glib-2-80

See merge request GNOME/glib!4060
2024-05-09 12:09:34 +00:00
Marco Trevisan (Treviño)
fe89e9f3cb
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-09 10:34:46 +01:00
Philip Withnall
d9d93579f0
2.80.2
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-08 16:29:04 +01:00
Philip Withnall
3360993402 Merge branch 'backport-4053-ibus-name-glib-2-80' into 'glib-2-80'
Backport !4053 “gdbusconnection: Allow name owners to have the syntax of a well-known name” to glib-2-80

See merge request GNOME/glib!4055
2024-05-08 15:23:36 +00:00
Michael Catanzaro
d2cfbb8eca Merge branch 'backport-4049-gvariant-docs-dir-glib-2-80' into 'glib-2-80'
Backport !4049 “Correct installation directory of GVariant specification” to glib-2-80

See merge request GNOME/glib!4054
2024-05-08 15:15:12 +00:00
Simon McVittie
3551143ecb
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 15:51:02 +01:00
Michael Catanzaro
35bccc46f9
Correct installation directory of GVariant specification
548ec9f186 accidentally moved the GVariant
spec to the toplevel /usr/share/doc directory, which is surely not
right. Let's move it back into the glib-2.0 subdirectory.

It's debatable whether this is the best place to install the GVariant
specification, since it's not part of the gi-docgen docs, but surely
it's much better than not putting it in any subdirectory.

Fixes #3351
2024-05-08 15:43:25 +01:00
Philip Withnall
d6bae28000 Merge branch 'cherry-pick-47866d25' into 'glib-2-80'
Backport "gdbusconnection: Fix test signal subscription ordering" to glib-2-80

See merge request GNOME/glib!4052
2024-05-08 14:40:03 +00:00
Ray Strode
a1ca2fc1bf 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.


(cherry picked from commit 47866d252f)
2024-05-07 23:16:01 +00:00
Philip Withnall
dd0e9590e7
2.80.1
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-07 15:50:30 +01:00
Philip Withnall
adc4e0dd5b Merge branch '2.80-bus-name-owners' into 'glib-2-80'
Backport !4038 “gdbusconnection: Don't deliver signals if the sender doesn't match” to glib-2-80

See merge request GNOME/glib!4039
2024-05-07 14:30:40 +00:00
Simon McVittie
ded4e7e025 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-06 22:44:09 +01:00
Hugo Carvalho
435102b78d Update Portuguese translation 2024-05-06 21:24:18 +00:00
Philip Withnall
b85f94bb0c Merge branch 'backport-4031-erofs-glib-2-80' into 'glib-2-80'
Backport !4031 “gdocumentportal: Handle EROFS and similar errors more gracefully” to glib-2-80

See merge request GNOME/glib!4032
2024-05-02 15:37:56 +00:00
Simon McVittie
a869dcb90b
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-02 12:31:51 +01:00
Simon McVittie
8c8f08304e
gdocumentportal: Factor out opening_ro_might_succeed()
No functional change.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-02 12:31:34 +01:00
Rachida SACI
47227a4c40 Update Kabyle translation 2024-05-01 14:55:04 +00:00
Simon McVittie
2b9ede6293 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 15:19:33 +01:00
Simon McVittie
7bf6cc5a8f 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 15:19:33 +01:00
Simon McVittie
1c9f335e90 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 15:19:33 +01:00
Simon McVittie
ad8e763f73 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 15:19:33 +01:00
Simon McVittie
d6c2a2f12e 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 15:19:33 +01:00
Simon McVittie
0bca1891a7 gdbusconnection: Stop storing sender_unique_name in SignalData
This will become confusing when we start tracking the owner of a
well-known-name sender, and it's redundant anyway. Instead, track the
1 bit of data that we actually need: whether it's a well-known name.

Strictly speaking this too is redundant, because it's syntactically
derivable from the sender, but only via extra string operations.
A subsequent commit will add a data structure to keep track of the
owner of a well-known-name sender, at which point this boolean will
be replaced by the presence or absence of that data structure.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
d31f0777d1 gdbusconnection: Factor out remove_signal_data_if_unused
No functional change, just removing some nesting. The check for whether
signal_data->subscribers is empty changes from a conditional that tests
whether it is into an early-return if it isn't.

A subsequent commit will add additional conditions that make us consider
a SignalData to be still in use and therefore not eligible to be removed.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
a8187079da gdbusconnection: Factor out add_signal_data()
No functional changes.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
91fe59eeef gdbusconnection: Factor out signal_data_new_take()
No functional changes, except that the implicit ownership-transfer
for the rule field becomes explicit (the local variable is set to NULL
afterwards).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
c5126b3308 gdbusconnection: Move SignalData, SignalSubscriber higher up
Subsequent changes will need to access these data structures from
on_worker_message_received(). No functional change here, only moving
code around.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
bd1bb4f5e0 gdbusprivate: Add symbolic constants for the message bus itself
Using these is a bit more clearly correct than repeating them everywhere.
To avoid excessive diffstat in a branch for a bug fix, I'm not
immediately replacing all existing occurrences of the same literals with
these names.

The names of these constants are chosen to be consistent with libdbus,
despite using somewhat outdated terminology (D-Bus now uses the term
"well-known bus name" for what used to be called a service name,
reserving the word "service" to mean specifically the programs that
have .service files and participate in service activation).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
e6cd64c66c tests: Add test coverage for signals that match the message bus's name
This is a special case of unique names, even though it's syntactically
a well-known name.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
b4b7411e67 tests: Add a test-case for what happens if a unique name doesn't exist
On GNOME/glib#3268 there was some concern about whether this would
allow an attacker to send signals and have them be matched to a
GDBusProxy in this situation, but it seems that was a false alarm.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
70a82ef96e tests: Add support for subscribing to signals from a well-known name
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Simon McVittie
a0de90583f tests: Add a data-driven test for signal subscriptions
This somewhat duplicates test_connection_signals(), but is easier to
extend to cover different scenarios.

Each scenario is tested three times: once with lower-level
GDBusConnection APIs, once with the higher-level GDBusProxy (which
cannot implement all of the subscription scenarios, so some message
counts are lower), and once with both (to check that delivery of the
same message to multiple destinations is handled appropriately).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 15:19:33 +01:00
Philip Withnall
7feaf2142f Merge branch 'backport-4028-gdbus-arg0-crash-glib-2-80' into 'glib-2-80'
Backport !4028 “gdbusconnection: Fix a crash on arg0 matching” to glib-2-80

See merge request GNOME/glib!4029
2024-05-01 10:34:25 +00:00
Philip Withnall
9c66880af0
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-05-01 10:53:22 +01:00
Leônidas Araújo
7b07b0e675 Update Brazilian Portuguese translation 2024-04-29 18:11:41 +00:00
Michael Catanzaro
7028651df0 Merge branch 'backport-4005-scan-build-fixes-glib-2-80' into 'glib-2-80'
Backport !4005 “Fix various bugs found by scan-build“ to glib-2-80

See merge request GNOME/glib!4025
2024-04-26 14:40:10 +00:00
Philip Withnall
705ce39b9a
gvariant-serialiser: Check offsets array is initialised before using it
When piecewise validating the offset table for a variable sized array,
it’s possible that the offset table (`offsets.array`) won’t actually
have been set by `gvs_variable_sized_array_get_frame_offsets()` iff the
serialised `GVariant` is not in normal form.

Add an additional check to guard against this. This will result in an
empty child variant being returned, as with other error handling paths
in `gvs_variable_sized_array_get_child()`.

This is a true positive spotted by scan-build. Thanks, scan-build.

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

Helps: #1767
2024-04-26 10:34:10 +01:00
Philip Withnall
dc2027e728
gparamspecs: Fix NULL pointer dereference
I’m not sure exactly how this code is supposed to work, so this might
not be the right fix. But there’s definitely a problem here, and it was
spotted by scan-build.

If `param_value_array_validate()` is entered with
`value->data[0].v_pointer == NULL && aspec->fixed_n_elements`, that `NULL`
will be stored in `value_array` too. `value->data[0].v_pointer` will
then be set to a new non-`NULL` array.

A few lines down, `value_array_ensure_size()` is called on
`value_array` – which is still `NULL` – and this results in a `NULL`
pointer dereference.

It looks like `value->data[0].v_pointer` and `value_array` are used
interchangeably throughout the whole of the function, so assign the new
value of `value->data[0].v_pointer` to `value_array` too.

My guess is that `value_array` is just a convenience alias for
`value->data[0].v_pointer`, because the latter is a real mouthful to
type or read.

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

Helps: #1767
2024-04-26 10:33:50 +01:00
Philip Withnall
7c7c00635e
gspawn: Fix use of uninitialised FDs on error path
Spotted by scan-build, an actual true positive result from it, and a
fiendish one too.

If any of the calls to `dupfd_cloexec()` (except the final one) fail,
the remainder of the `duped_source_fds` array would have been left
uninitialised.

The code in `out_close_fds` would have then called `g_clear_fd()` on an
uninitialised FD, with unpredictable results.

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

Helps: #1767
2024-04-26 10:33:41 +01:00
Philip Withnall
21f5e175d4
xdgmimeglob: Fix a memory leak on a duplicate-entry path
Rather than `strdup()`ing strings when passing them into
`_xdg_glob_list_append()`, `strdup()` them *inside* the function
instead.

This avoids a leak in the case that the list entry (tuple of `data` and
`mime_type`) already exists in the list.

This has been upstreamed as
https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/36.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-26 10:33:25 +01:00
Philip Withnall
747e3af998
gdbusconnection: Fix user_data leaks on error
There were a couple of functions in `GDBusConnection` which take a
`user_data` argument, but which then leak it if they error out early.

A true positive spotted by scan-build!

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

Helps: #1767
2024-04-26 10:33:03 +01:00
Philip Withnall
39f0e6d435
girffi: Fix ffi_cif leaks on error return paths
Spotted by scan-build.

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

Helps: #1767
2024-04-26 10:32:53 +01:00
Philip Withnall
4141eea257
girffi: Add hints to indicate ownership transfer into ffi_cif
scan-build thinks that the `atypes` array is leaked, but it’s not.
Ownership is transferred into the `ffi_cif` structure, and it’s
eventually freed in `gi_callable_info_destroy_closure()`.

Try and help the static analysis by adding an explicit ownership
transfer annotation. It probably won’t help.

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

Helps: #1767
2024-04-26 10:32:47 +01:00
Philip Withnall
e2c3581e37
gdbusconnection: Ensure out_serial return value is always set
There were some error paths where it wasn’t set, returning an
uninitialised value to the caller.

Spotted by scan-build.

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

Helps: #1767
2024-04-26 10:32:32 +01:00
Michael Catanzaro
abdff22528 Merge branch 'backport-4019-inotify-limit-glib-2-80' into 'glib-2-80'
Backport !4019 “gunixmounts: Use fallback if libmount monitoring fails” to glib-2-80

See merge request GNOME/glib!4021
2024-04-23 20:07:49 +00:00
Ondrej Holy
ed24edd7c8 gunixmounts: Use fallback if libmount monitoring fails
The recently added libmount-based unix mount monitoring may fail when the
device exceeds inotify limits. Let's fallback to the older implementation
in case of the `mnt_monitor_get_fd` function failure. This among others
fixes tracker-miners failures caused by seccomp rules.

Fixes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/315
2024-04-23 12:50:06 +01:00
Andika Triwidada
30ec6c8381 Update Indonesian translation 2024-04-22 11:02:05 +00:00
Christian Kirbach
53e16feca5 Update German translation 2024-04-18 20:32:01 +00:00
Philip Withnall
55a6167773 Merge branch 'mcatanzaro/unused-cmph' into 'glib-2-80'
Backport "Remove unused cmph files" for glib-2-80

See merge request GNOME/glib!4004
2024-04-12 18:39:49 +00:00