Commit Graph

30279 Commits

Author SHA1 Message Date
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
Philip Withnall
2d5fc78f63
gtestutils: Add an assertion to squash a scan-build false positive
scan-build thinks there’s a potential `NULL` pointer dereference of some
of the members of `msg->strings`, because it doesn’t know about the
implicit invariant that the length of `msg->strings` is
`msg->n_strings`.

Ideally we want an assertion like `g_assert (g_strv_length
(msg->strings) == msg->n_strings)`, but that’s not very performant, so
just settle for a non-`NULL` assertion on each loop iteration to give
scan-build the hint it needs.

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

Helps: #1767
2024-04-25 23:58:13 +01:00
Philip Withnall
cf940496df
ghostutils: Add a missing precondition check to g_hostname_to_unicode()
This helps out scan-build, which otherwise thinks there could be a
`NULL` pointer dereference.

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

Helps: #1767
2024-04-25 23:58:08 +01:00
Philip Withnall
057f0fcbfb
gdatetime: Fix a maybe-uninitialized warning
scan-build thinks that `tmp` can be dereferenced before it’s all been
assigned to. I don’t think that’s the case, because the number of
elements in it which have been assigned to is tracked as `i`. But static
analysers find that kind of state tracking hard to reason about, so
let’s just zero-initialise the array to simplify things.

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

Helps: #1767
2024-04-25 23:58:04 +01:00
Philip Withnall
f1d5a71bbc
girparser: Silence a scan-build NULL pointer dereference warning
It’s very obviously a false positive, as `str` has been added to on the
previous line, so can’t be `(void *) 0`. Not sure what scan-build is
thinking.

I’d rather not have this assertion (it doesn’t help the programmer’s
understanding of the code), but I would also rather have scan-build
running with no warnings so that it can helpfully catch newly-introduced
errors in future.

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

Helps: #1767
2024-04-25 23:57:59 +01: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
Philip Withnall
9f3322c784
gdbusdaemon: Disable scan-build for GDBusDaemon name refcounting
See the code comment. scan-build can’t handle analysis over the
refcounts, so consistently complains about potential use-after-free
errors in the code, essentially because:
 * It understands `name_unref()`, but completely ignores `name_ref()`
 * The code often calls `name_unref()` on the ‘wrong’ pointer, in the
   sense that it knows that if another struct exists, that struct holds
   a ref on a `Name`, but without actually having a pointer to the
   `Name`. So the code calls `name_unref (name); name_unref (name)`.
   That’s valid, but quite understandably looks like a recipe for a
   use-after-free.

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

Helps: #1767
2024-04-25 23:57:51 +01:00
Philip Withnall
672a33002e
gunixmounts: Squash a static analyser false positive
scan-build thinks that there can be a `NULL` pointer dereference of
`error` here because it doesn’t understand that the function return
value and `GError` are related: when a valid return value is returned,
the error is `NULL` and vice-versa.

Try and make that clearer to the static analyser by checking whether the
error is `NULL`, rather than the return value.

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

Helps: #1767
2024-04-25 23:57:46 +01:00
Philip Withnall
a1ff120a98
gsrvtarget: Silence false positive NULL pointer dereference
scan-build thinks there could be a `NULL` pointer dereference of
`t->data` here. It’s wrong, so add an assertion to try and help it
understand the control flow.

The loop is exited as soon as a target is found whose weight is greater
than or equal to a random value between 0 and the sum of all the weights
in the set of remaining targets in the loop. By definition, the last
target in the loop always satisfies this condition, so a target will
always be chosen, and hence `t` will never be `NULL` within the loop.

`t->data` will never be `NULL` by construction of the target list.

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

Helps: #1767
2024-04-25 23:57:41 +01:00
Philip Withnall
066298b6ef
gdbusconnection: Fix a false positive memory leak from scan-build
scan-build thinks that `data` could be leaked. It’s not, though; it’s
passed as the `user_data` to `g_dbus_connection_register_object()` along
with its free function.

Try and persuade scan-build that there’s no leak by annotating the
transfer.

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

Helps: #1767
2024-04-25 23:57:36 +01:00