Commit Graph

30146 Commits

Author SHA1 Message Date
Philip Withnall
48988a4098
girepository: Make gi_repository_find_by_gtype() deterministic
When faced with a `GType` which is present in multiple typelibs, the old
implementation was not deterministic, as it iterated over a hash table
of typelibs. The iteration order of a hash table is not deterministic.

Use the new `ordered_typelibs` and `ordered_lazy_typelibs` arrays to
iterate instead, making the order deterministic.

Add a unit test to check this. In particular, to check that symbols
which are present in both `Gio` and `GioUnix` are correctly resolved as
being from `GioUnix`.

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

Helps: #3303
2024-05-16 23:32:02 +01:00
Philip Withnall
25b7ecf895
gitypelib: Fix iterating through typelib prefixes
The iteration code used `g_string_overwrite_len()` to try and simplify
buffer allocation and growth, but seemingly forgot to handle the fact
that it doesn’t nul-terminate what it overwrites: the method is intended
to be used to splice bits into longer strings, not to overwrite an
entire nul-terminated string.

This meant that when iterating over a comma-separated `c_prefix` like
`GUnix,G`, on the second iteration `g_string_overwrite_len()` would be
used to write `G` into index 0 of the already-set `GUnix` string in the
buffer, leading to the first iteration happening all over again and the
`G` prefix being ignored.

This led to symbols failing to be matched to the `GioUnix` typelib, even
though they should have been.

This will be checked by a test in the following commit.

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

Helps: #3303
2024-05-16 23:31:56 +01:00
Philip Withnall
04bdf50c68
girepository: Fix a typo in a code comment
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 23:31:49 +01:00
Philip Withnall
7e3ec9a8ae
girepository: Keep an ordered list of the loaded typelibs
There are various places where the set of typelibs is iterated over or
returned in an ordered way. In order to keep results deterministic and
reproducible, we need to keep this set ordered.

Keep a `GPtrArray` of the typelibs (one for fully-loaded ones and one
for lazy ones) alongside the existing hash tables. This will be used for
iteration in the next few commits.

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

Helps: #3303
2024-05-16 23:31:43 +01:00
Philip Withnall
2c379a35ba Merge branch 'backport-4065-girepository-bitfield-glib-2-80' into 'glib-2-80'
Backport !4065 “girepository: Don't assume a bitfield has a fixed size” to glib-2-80

See merge request GNOME/glib!4074
2024-05-16 21:38:28 +00:00
Emmanuele Bassi
2d60dc1539 Merge branch 'backport-4073-dbus-export-glib-2-80' into 'glib-2-80'
Backport !4073 “gmenuexporter: Fix a NULL pointer dereference on an error handling path” to glib-2-80

See merge request GNOME/glib!4077
2024-05-16 12:08:26 +00:00
Philip Withnall
043a06debb
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-16 12:20:07 +01:00
Philip Withnall
5f5667b2a0
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-16 12:19:57 +01:00
Philip Withnall
c2ec54d641 Merge branch 'backport-4059-leak-fixes-glib-2-80' into 'glib-2-80'
Partially backport !4059 “tests: Fix various memory leaks and valgrind / ASAN errors” to glib-2-80

See merge request GNOME/glib!4070
2024-05-15 13:55:16 +00:00
Marco Trevisan (Treviño)
9c611f6ef9
glib/tests/mapping: Unref the mapped file on exit 2024-05-15 13:00:01 +01:00
Marco Trevisan (Treviño)
116312f089
glib/tests/mapping: Check the exit status of the child process
In this way if it fails for some memory error we can track it
2024-05-15 12:59:55 +01:00
Marco Trevisan (Treviño)
5fc08f60b5
girepository/introspection: Properly check for sanitizer value
The sanitizer option is set to 'none' when not used
2024-05-15 12:59:48 +01:00
Marco Trevisan (Treviño)
c6770f964c
glib/tests/gutils-user-database: Add test dependency on preload library
We do preload the library but that's not set as test dependency and so
it may not be built
2024-05-15 12:59:42 +01:00
Marco Trevisan (Treviño)
a2111bec69
glib/tests/unicode: Cleanup allocated old locale if tests is skipped 2024-05-15 12:59:35 +01:00
Marco Trevisan (Treviño)
e4d369d5f4
gio/tests/gsettings: Cleanup allocated new locales 2024-05-15 12:59:28 +01:00
Marco Trevisan (Treviño)
5201650b21
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-15 12:59:22 +01:00
Adam Sampson
62b11360da
girepository: Don't assume a bitfield has a fixed size
The type used when declaring a bitfield member of a struct doesn't
affect the amount of space allocated for it - only whether it's signed
or unsigned. In standard C99 (6.2.7.1), only _Bool, signed int and
unsigned int or typedefs to them are allowed as bitfield types, but GCC
allows other integer types as an extension.

In this case, the GIBaseInfo and GIBaseInfoStack structs are meant to
have identical layout. However, type_is_embedded was declared as an
unsigned bitfield in the former and a uint32_t in the latter. This was
harmless on most platforms because the following member is an aligned
pointer, but (for example) on m68k-linux-gnu pointers only need to be
16-bit aligned, so GCC only allocates 16 bits for the bitfield.

Change the type in the declaration to unsigned int, and add an padding
bitfield following it to ensure there's space for 32 bits on all
platforms in the future.

Signed-off-by: Adam Sampson <ats@offog.org>
2024-05-15 12:57:44 +01:00
Emmanuele Bassi
71a143f32f Merge branch 'backport-4066-msys2-ci-fix-glib-2-80' into 'glib-2-80'
Backport !4066 “Fix several GCC 14 warnings to please msys2-mingw32 CI” to glib-2-80

See merge request GNOME/glib!4072
2024-05-15 11:20:40 +00:00
Philip Withnall
88e0dca208
tests: Fix transposed arguments to g_aligned_alloc()
Spotted by GCC 14’s `-Werror=calloc-transposed-args`. Thanks, GCC 14.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-15 11:57:16 +01:00
Philip Withnall
8714b87dbe
tests: Ignore -Wdiscarded-qualifiers with volatile atomics tests
GCC 14 now emits this warning with the tests:
```
In file included from ../glib/gthread.h:34,
                 from ../glib/gasyncqueue.h:34,
                 from ../glib/glib.h:34,
                 from ../glib/tests/atomic.c:14:
../glib/tests/atomic.c: In function 'test_types':
../glib/gatomic.h:140:5: error: argument 2 of '__atomic_store' discards 'volatile' qualifier [-Werror=discarded-qualifiers]
  140 |     __atomic_store (gaps_temp_atomic, &gaps_temp_newval, __ATOMIC_SEQ_CST); \
      |     ^~~~~~~~~~~~~~
../glib/tests/atomic.c:139:3: note: in expansion of macro 'g_atomic_pointer_set'
  139 |   g_atomic_pointer_set (&vp_str_vol, NULL);
      |   ^~~~~~~~~~~~~~~~~~~~
cc1.exe: all warnings being treated as errors
```

I can’t think of a way to cast around this in the definition of
`g_atomic_pointer_set()` without making the behaviour worse (less type
safe) for modern non-volatile atomic variables.

We would like to strongly nudge users of GLib away from declaring atomic
variables as `volatile`, so letting another compiler warning be emitted
when they do is not the end of the world. As long as it doesn’t stop old
code compiling (without `-Werror`).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-15 11:57:10 +01:00
Marco Trevisan (Treviño)
2f35c32c34
vsaprintf: Use proper size for mp_limb_t to please msys2-mingw32 CI 2024-05-15 11:57:03 +01:00
Marco Trevisan
adb57fb40f Merge branch 'backport-4058-gir-test-deps-glib-2-80' into 'glib-2-80'
Backport !4058 “Tests: Build fixes when running `meson test` without previous builds“ to glib-2-80

See merge request GNOME/glib!4061
2024-05-09 15:20:50 +00:00
Marco Trevisan (Treviño)
b48b7b2a84
girrepository/tests: Add full gir dependencies on tests
Tests may have runtime dependencies that are related to the typelib
dependencies, so we need to satify them or the tests will fail at
runtime if we're not building their prerequisite for other reasons.

That's saying that the tests are currently failing when explicitly
running as standalone in meson.

Co-Authored-By: Philip Withnall <philip@tecnocode.co.uk>
2024-05-09 15:36:54 +01:00
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