26150 Commits

Author SHA1 Message Date
Simon McVittie
f8a2a0f4ac 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 19:28:33 +01:00
Simon McVittie
34c89e33be 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 19:28:33 +01:00
Simon McVittie
fe0eb13e69 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.

[Backported to glib-2-74, resolving minor conflicts]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 19:28:33 +01:00
Simon McVittie
bc529198f9 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 19:28:33 +01:00
Simon McVittie
df6d9ed691 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 19:28:33 +01:00
Simon McVittie
7494c996a0 gdbusconnection: Factor out add_signal_data()
No functional changes.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 19:28:33 +01:00
Simon McVittie
bc9638343c 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 19:28:33 +01:00
Simon McVittie
7ae58aa743 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 19:28:33 +01:00
Simon McVittie
adc9088b5e 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 19:28:33 +01:00
Simon McVittie
3f4f843157 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 19:28:33 +01:00
Simon McVittie
0bc60b3e4b 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 19:28:33 +01:00
Simon McVittie
23ab755303 tests: Add support for subscribing to signals from a well-known name
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 19:28:33 +01:00
Simon McVittie
945830178a 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).

[Backported to glib-2-74, resolving conflicts in gio/tests/meson.build]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 19:28:33 +01:00
Simon McVittie
67052fedf4 gdbusconnection: Make a backport of g_set_str() available
A subsequent commit will need this. Copying all of g_set_str() into a
private header seems cleaner than replacing the call to it.

Helps: GNOME/glib#3268
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 19:27:30 +01:00
Philip Withnall
0a73fffe39 gdbusmessage: Cache the arg0 value
Technically we can’t rely on it being kept alive by the `message->body`
pointer, unless we can guarantee that the `GVariant` is always
serialised. That’s not necessarily the case, so keep a separate ref on
the arg0 value at all times.

This avoids a potential use-after-free.

Spotted by Thomas Haller in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3720#note_1924707.

[This is a prerequisite for having tests pass after fixing the
vulnerability described in glib#3268, because after fixing that
vulnerability, the use-after-free genuinely does happen during
regression testing. -smcv]

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

Helps: #3183, #3268
(cherry picked from commit 10e9a917be7fb92b6b27837ef7a7f1d0be6095d5)
2024-05-01 19:26:07 +01:00
Daniel Rusek
fa55ff31ee Update Czech translation 2023-09-17 13:04:28 +00:00
Philip Withnall
c6d1380489
2.74.7
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.74.7
2023-04-14 11:42:31 +01:00
Marco Trevisan
bd9dd2ef1b Merge branch 'backport-3359-win32-strcmp-glib-2-74' into 'glib-2-74'
Backport !3359 “GWin32AppInfo: Fix g_str_has_prefix() check” to glib-2-74

See merge request GNOME/glib!3360
2023-04-05 14:32:08 +00:00
Luca Bacci
830bcbcf29 GWin32AppInfo: Fix g_str_has_prefix() check
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2972
2023-04-05 15:11:11 +01:00
Philip Withnall
a1e169129c Merge branch 'backport-3317-win32-null-checks-glib-2-74' into 'glib-2-74'
Backport !3317 “GWin32AppInfo: Add NULL string checks” to glib-2-74

See merge request GNOME/glib!3320
2023-03-13 10:32:07 +00:00
Luca Bacci
6d1471815e GWin32AppInfo: Add NULL string checks
Fixes #2922
2023-03-10 16:15:21 +00:00
Philip Withnall
0559f4b8b6 Merge branch 'skip-test-under-sandbox-2.74' into 'glib-2-74'
tests: Skip assert-msg-test.py if gdb fails

See merge request GNOME/glib!3307
2023-03-06 15:36:48 +00:00
Matt Turner
f36c8876e7 tests: Skip assert-msg-test.py if gdb fails
Similar to commit 6e44151bf74d, skip the test if gdb is unable to read
/proc/PID/mem, which gdb does as a fallback if ptrace is unavailable.

This allows the test to skip when run under Gentoo's sandbox.

(cherry picked from commit 19a8df9d8bff279a55b0fa3bb7ba4fbf7fcbefa8)
2023-03-03 16:32:02 -05:00
Simon McVittie
faf87df568 Merge branch 'translation-47-fix-string-break-glib-2-74' into 'glib-2-74'
gdbus: Fix an accidental string freeze break

See merge request GNOME/glib!3303
2023-03-02 13:55:11 +00:00
Philip Withnall
be83335eca gdbus: Fix an accidental string freeze break
Commit d982c8607 accidentally broke the string freeze on `glib-2-74` by
adding a new translatable string.

We can avoid that by reusing an existing string which has a similar
meaning.

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

Fixes: https://gitlab.gnome.org/Teams/Translation/Coordination/-/issues/47
2023-03-02 12:37:48 +00:00
Simon McVittie
f34ab2af3e Merge branch 'backport-3297-use-after-free-gdbus-method-invocation-glib-2-74' into 'glib-2-74'
Backport !3297 “gdbusinterfaceskeleton: Fix a use-after-free of a GDBusMethodInvocation” to glib-2-74

See merge request GNOME/glib!3298
2023-03-02 12:32:23 +00:00
Simon McVittie
925ae2fba1 Merge branch 'backport-3272-gdbus-auth-buffering-glib-2-74' into 'glib-2-74'
Backport !3272 “gdbus: Never buffer reads during server authentication” to glib-2-74

See merge request GNOME/glib!3300
2023-03-02 12:31:06 +00:00
Marius Vollmer
d982c86078 gdbus: Never buffer reads during server authentication
Otherwise, the content of the buffer is thrown away when switching
from reading via a GDataInputStream to unbuffered reads when waiting
for the "BEGIN" line.

(The code already tried to protect against over-reading like this by
using unbuffered reads for the last few lines of the auth protocol,
but it might already be too late at that point.  The buffer of the
GDataInputStream might already contain the "BEGIN" line for example.)

This matters when connecting a sd-bus client directly to a GDBus
client.  A sd-bus client optimistically sends the whole auth
conversation in one go without waiting for intermediate replies.  This
is done to improve performance for the many short-lived connections
that are typically made.
2023-02-23 14:27:12 +00:00
Philip Withnall
a5dde63046
2.74.6
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.74.6
2023-02-23 13:54:27 +00:00
Philip Withnall
2da9ca2727 gdbusconnection: Make GDBusMethodInvocation transfer a bit clearer
Add a missing steal call in `schedule_method_call()`. This introduces no
functional changes, but documents the ownership transfer more clearly.

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

Helps: #2924
2023-02-23 13:05:57 +00:00
Philip Withnall
b29892237d gdbusinterfaceskeleton: Fix a use-after-free of a GDBusMethodInvocation
This `GDBusMethodInvocation` may be shared across threads, with no
guarantee on the strong ref in one thread outlasting any refs in other
threads — so it needs a ref in this helper struct.

This should fix a use-after-free where the `GDBusMethodInvocation` is
freed from `g_value_unset()` after `g_signal_emit()` returns in
`dispatch_in_thread_func()` in one thread; but then dereferenced again
in `g_source_destroy_internal()` from another thread.

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

Fixes: #2924
2023-02-23 13:05:57 +00:00
Philip Withnall
d90fbc3636 gdbusinterfaceskeleton: Remove an unnecessary helper struct member
The `GDBusInterfaceSkeleton` is already stored as the source object of
the `GTask` here, with a strong reference.

Storing it again in the task’s data struct is redundant, and makes it
look like the `GDBusInterfaceSkeleton` is being used without holding a
strong reference. (There’s not actually a bug there though: the strong
reference from the `GTask` outlives the data struct, so is sufficient.)

Remove the unnecessary helper struct member to clarify the code a bit.

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

Helps: #2924
2023-02-23 13:05:57 +00:00
Tim Sabsch
290c4b7709 Update German translation 2023-02-18 14:48:19 +00:00
Philip Withnall
bee86260bb Merge branch 'backport-3237-wspawnve-win32-glib-2-74' into 'glib-2-74'
Backport !3237 “Fix safe_wspawnve #define” to glib-2-74

See merge request GNOME/glib!3239
2023-01-26 17:02:48 +00:00
Hernan Martinez
5602caee9d Fix safe_wspawnve #define 2023-01-26 14:27:39 +00:00
Ekaterine Papava
fb218fa737 Update Georgian translation 2023-01-25 06:53:25 +00:00
Philip Withnall
39a71aff37
2.74.5
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.74.5
2023-01-19 13:44:30 +00:00
Philip Withnall
788e1cf888 Merge branch 'backport-3213-variant-text-performance-glib-2-74' into 'glib-2-74'
Backport !3213 “gvariant: Optimise g_variant_print() for nested maybes” to glib-2-74

See merge request GNOME/glib!3214
2023-01-18 12:46:35 +00:00
Philip Withnall
ab8cdb07de gvariant: Remove some unnecessary type assertions on a hot path
While checking the validity of a `GVariantTypeInfo` is good, this code
path is very hot, and I’ve never seen these assertions catch a bug in
practice.

Lean more towards the performance side of the performance/correctness
tradeoff in this case, by removing the assertions here.

They remain in place in a number of other `GVariantTypeInfo` code paths,
so invalid `GVariantTypeInfo` pointers should hopefully still be caught
quickly.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-18 12:15:47 +00:00
Philip Withnall
8373f328bd gvariant: Remove redundant g_variant_serialised_n_children() calls
These functions were previously calling
`g_variant_serialised_n_children()` twice just to validate the input, in
the case that the input was a serialised variant.

That’s not necessary, and checking the number of children in a
serialised variant is not necessarily cheap.

Move the checks around so that the number of children is only checked
once on each code path. This doesn’t introduce any functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-18 12:15:47 +00:00
Philip Withnall
53702d68c4 gvariant: Optimise g_variant_print() for nested maybes
As with commit 9ae59bd647882bcb33103331255a5149d2fb90d2, deeply nested
maybes in an array can be exploited by a malicious caller to cause a
geometric increase in processing time and number of `GVariant` instances
handled by the `g_variant_print()` code.

Optimise this by skipping recursing through most of the chain of maybes,
thus avoiding all the setup checks in each recursive call.

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

oss-fuzz#54577
2023-01-18 12:15:47 +00:00
Philip Withnall
f068347b14 gvariant: Factor out some common calls to g_variant_get_type_string()
When printing a `GVariant`.

This introduces no functional changes, but should speed things up a
little bit when printing out arrays.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-18 12:15:47 +00:00
Marco Trevisan
c28829fe87 Merge branch 'backport-3178-mtime-fix-glib-2-74' into 'glib-2-74'
Backport !3178 “glocalfileinfo: Don't reset mtime tv_sec when setting tv_usec” to glib-2-74

See merge request GNOME/glib!3182
2023-01-17 14:55:00 +00:00
Marco Trevisan
78925535f9 Merge branch 'backport-3200-write-limits-glib-2-74' into 'glib-2-74'
Backport !3200 “gfileutils: Use 'write' with 'count' <= max value of its return type” to glib-2-74

See merge request GNOME/glib!3204
2023-01-17 14:28:08 +00:00
CCode
dfd070cea4 gfileutils: Use 'write' with 'count' <= max value of its return type
Limit `count` so that `write` can properly report the number of written bytes.

Limits:
 - POSIX: `SSIZE_MAX`
 - Windows: `INT_MAX`

Fixes: #2883
2023-01-16 13:09:55 +00:00
Marco Trevisan
40233516bc Merge branch 'backport-3194-regex-invalid-memory-access-glib-2-74' into 'glib-2-74'
Backport !3194 “gregex: Prevent invalid memory access for unmatched subpatterns” to glib-2-74

See merge request GNOME/glib!3197
2023-01-14 03:19:57 +00:00
Philip Withnall
0d99c57e22 gregex: Prevent invalid memory access for unmatched subpatterns
Based on a test by Emmanuel Pacaud.

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

Fixes: #2881
2023-01-12 15:37:21 +00:00
Emmanuele Bassi
3ba701a499 Merge branch 'backport-3160-win32-app-info-glib-2-74' into 'glib-2-74'
Backport !3160 “GWin32AppInfo: Check for local file path first” to glib-2-74

See merge request GNOME/glib!3166
2023-01-05 18:56:52 +00:00
Maxim Mikityanskiy
b8cd4298e5 glocalfileinfo: Don't reset mtime tv_sec when setting tv_usec
Fix a regression that appeared after adding support for nanosecond
timestamps to set_mtime_atime(). User-visible effect: when copying a
file from a gvfs MTP mountpoint to the local filesystem, the file's
mtime is set to 0.

This behavior happens when setting G_FILE_ATTRIBUTE_TIME_MODIFIED first,
then G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC. Setting the second attribute
ends up in set_mtime_atime() with mtime_usec_value set, and mtime_value
== NULL. When mtime_value is NULL, the tv_sec part of the timestamp
should be fetched by lazy_stat(), but set_mtime_atime() fails to assign
it properly, and tv_sec stays at 0, leading to losing the main part of
the timestamp.

Fix the issue by setting times_n[1].tv_sec to the value fetched from
lazy_stat().

Fixes: b33ef610deef ("Add functionality to preserve nanosecond timestamps")
Fixes: 15cb123c824c ("glocalfileinfo: don't call both utimes and utimensat")
Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
2023-01-05 14:41:14 +00:00
Nart Tlisha
433464b3f9 Update Abkhazian translation 2023-01-05 12:44:47 +00:00