Commit Graph

30390 Commits

Author SHA1 Message Date
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
3fca627241 Merge branch 'wip/3v1n0/valgrind-ignore-alternate-stack-contents-check' into 'main'
glib/tests/unix: Do not perform stack memory checks under valgrind

Closes #3337

See merge request GNOME/glib!4050
2024-05-09 14:54:46 +00:00
Marco Trevisan
8a5612440e Merge branch 'tests-build-fixes' into 'main'
Tests: Build fixes when running `meson test` without previous builds

See merge request GNOME/glib!4058
2024-05-09 14:27:38 +00:00
Marco Trevisan (Treviño)
3de5264f24 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:48:58 +02:00
Marco Trevisan (Treviño)
5aafaa0cc9 glib/tests/constructor: Add test dependency on constructor_lib
Otherwise we may build the test but not its dependent library
2024-05-09 15:48:32 +02:00
Marco Trevisan (Treviño)
c894e89720 glib/tests/unix: Do not perform stack memory checks under valgrind
When running the alternate stack tests under valgrind the stack memory
gets corrupted that we've initialized gets somehow corrupted and this
causes a read-error while reading the stack memory area.

No matter if we use instead malloc-allocated or mmap'ed memory areas,
the result is always the same: a memory error while reading it.

  Reading byte 2645
  Reading byte 2646
  Reading byte 2647
  Reading byte 2648
  ==46100== Invalid read of size 1

Now this memory is definitely stack-allocated and unless the valgrind
stack gets corrupted, there's no way it could have been removed.

I quite trust that this is some valgrind problem only though since no
other memory analyzer I've tried (memory sanitizer mostly) has
highlighted any issue with this.

As per this, since the main point of the test was just checking if
signals are delivered properly even when using an alternate stack, I
think that we can just safely run a simpler version of the test when
running under valgrind. This implies assuming that sigaltstack()
does what is supposed to do, without us double-checking it, but I guess
we can trust that (especially because we're still testing it when not
using valgrind).

Closes: #3337
2024-05-09 15:42:32 +02:00
Philip Withnall
651beec963 Merge branch 'wip/3v1n0/gmessage-arg0-leak-fix' into 'main'
gdbusmessage: Clean the cached arg0 when setting the message body

See merge request GNOME/glib!4057
2024-05-09 09:30:36 +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
Philip Withnall
c1fdfeddab Merge branch 'wip/smcv/issue3353' into 'main'
gdbusconnection: Allow name owners to have the syntax of a well-known name

Closes #3353

See merge request GNOME/glib!4053
2024-05-08 14:46:08 +00: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
Philip Withnall
db28af7da6 Merge branch 'mcatanzaro/3351' into 'main'
Correct installation directory of GVariant specification

Closes #3351

See merge request GNOME/glib!4049
2024-05-08 14:37:07 +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
Michael Catanzaro
cd45ba8638 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-07 14:24:38 -05:00
Marco Trevisan
cc5445ee04 Merge branch 'gapplication-error-path-leak' into 'main'
gapplication: Fix a small leak on an error handling path

See merge request GNOME/glib!4045
2024-05-07 17:09:34 +00: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
Hugo Carvalho
26c590015a Update Portuguese translation
(cherry picked from commit 435102b78d)
2024-05-06 21:24:28 +00: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
Philip Withnall
928b66898c Merge branch 'main' into 'main'
link with -latomic when needed

See merge request GNOME/glib!4034
2024-05-03 20:02:48 +00:00
Fabrice Fontaine
4e6dc4dee0 link with -latomic when needed
Some architecture such as sparc and some flavors of arm needs -latomic
to avoid the following build failure:

gthread-posix.c:(.text+0xda8): undefined reference to `__atomic_compare_exchange_4'

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2024-05-02 17:54:52 +02:00
Philip Withnall
da9545baaf Merge branch 'wip/smcv/documents-portal-erofs' into 'main'
gdocumentportal: Handle EROFS and similar errors more gracefully

See merge request GNOME/glib!4031
2024-05-02 11:30:52 +00: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
Marco Trevisan
4bd416f0ff Merge branch '3342-arg0-match-crash' into 'main'
gdbusconnection: Fix a crash on arg0 matching

Closes #3342

See merge request GNOME/glib!4028
2024-04-30 20:42:16 +00: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
Philip Withnall
740f2ea489 Merge branch 'jsparber/dbus_multiple_parameters' into 'main'
GApplication: Allow multiple parameters for D-Bus activation

Closes #3333

See merge request GNOME/glib!4026
2024-04-30 13:46:31 +00:00
Leônidas Araújo
872927c307 Update Brazilian Portuguese translation
(cherry picked from commit 7b07b0e675)
2024-04-29 18:11:49 +00: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
Yuri Chornoivan
5488829638 Update Ukrainian translation 2024-04-28 06:02:01 +00:00
Michael Catanzaro
202188c5bf Merge branch 'wip/pwithnall/datetime-non-literal-null-conversion' into 'main'
gdatetime: Fix string type used to initialise array

See merge request GNOME/glib!4024
2024-04-26 14:39:23 +00:00
Philip Withnall
e12e81a02d
gdatetime: Fix string type used to initialise array
This fixes commit 057f0fcbfb. I didn’t
notice that `tmp` is an array of strings, not an array of chars, and
somehow my compiler didn’t warn. Seems only the macOS CI job is spotting
the problem here.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-26 10:28:47 +01:00
Philip Withnall
640ff0c4da Merge branch 'scan-build2-the-false-positives' into 'main'
Squash various false positives from scan-build

Closes #1767

See merge request GNOME/glib!4007
2024-04-25 23:55:35 +00:00
Philip Withnall
9fc63f93b4
gclosure: Delete old commented-out non-thread-safe code
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-26 00:21:15 +01:00
Philip Withnall
b1b8166a8a
ci: Make scan-build errors fatal in CI
\o/

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

Fixes: #1767
2024-04-25 23:58:34 +01:00
Philip Withnall
b1bafda881
gvariant: Simplify GVariantType check in g_variant_format_string_scan_type()
Rather than returning through `G_VARIANT_TYPE`, which scan-build doesn’t
seem to fully understand ownership transfers through, just return `new`
directly, and do the `is_valid()` check separately.

The new code is equivalent to the old code, but squashes a scan-build
false positive around leaking `dest`. (See also: the previous commit.)

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

Helps: #1767
2024-04-25 23:58:30 +01:00
Philip Withnall
156c1496ba
gvariant: Rework array iteration in g_variant_format_string_scan_type()
This introduces no functional changes. Switch from incrementing a
pointer to incrementing a counter and using array indexing.

This squashes a scan-build false positive, where it can’t choose which
of `dest` and `new` ‘own’ the newly allocated memory, so it kind of
assumes both do, and then warns there’s a potential leak of `dest` when
the function returns. In actual fact, ownership of the memory is
returned via `new`.

Partly this might be masked through use of the `G_VARIANT_TYPE` macro,
which the following commit will address.

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

Helps: #1767
2024-04-25 23:58:23 +01:00
Philip Withnall
79be995c0c
gtimezone: Add a missing precondition assertion
Otherwise scan-build thinks there could be `NULL` pointer dereference of
the `tz`. (There can’t be, it’s a false positive. 🤫)

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

Helps: #1767
2024-04-25 23:58:18 +01:00