21653 Commits

Author SHA1 Message Date
Simon McVittie
a1e32f0a40 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-07 19:00:27 +02:00
Simon McVittie
70e07fcf9a 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-07 19:00:27 +02:00
Simon McVittie
0d8d384845 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-07 19:00:27 +02:00
Simon McVittie
d5fd16dc84 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-07 19:00:27 +02:00
Simon McVittie
e2e8cf713f 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.

[Backport to 2.66.x: fix minor conflicts]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-07 19:00:27 +02:00
Simon McVittie
257aac825a 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-07 19:00:27 +02:00
Simon McVittie
9533ea7a3c 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-07 19:00:27 +02:00
Simon McVittie
fad6e0362a gdbusconnection: Factor out add_signal_data()
No functional changes.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-07 19:00:27 +02:00
Simon McVittie
98f5ad2c22 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-07 19:00:27 +02:00
Simon McVittie
c6d202b635 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.

[Backport to 2.66.x: fix minor conflicts]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-07 19:00:27 +02:00
Simon McVittie
593ed5ded5 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-07 19:00:27 +02:00
Simon McVittie
0a7da80a98 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-07 19:00:27 +02:00
Simon McVittie
3ef5dad257 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-07 19:00:27 +02:00
Simon McVittie
1ae5e8c9cd tests: Add support for subscribing to signals from a well-known name
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-07 19:00:27 +02:00
Simon McVittie
8881cb6d76 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).

[Backport to 2.66.x: fix minor conflicts]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-07 19:00:27 +02:00
Simon McVittie
aeb13ae9be 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-07 19:00:27 +02:00
Philip Withnall
f3701217c7 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-07 19:00:27 +02:00
Philip Withnall
ddf2d4c7fa 2.64.6
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.64.6
2020-10-01 13:30:27 +01:00
Sebastian Dröge
1a3c7c5982 Merge branch 'backport-1671-datetime-negative-overflow-glib-2-64' into 'glib-2-64'
Backport !1671 “ gdatetime: Avoid integer overflow creating dates too far in the past” to glib-2-64

See merge request GNOME/glib!1672
2020-10-01 11:44:05 +00:00
Philip Withnall
2e5778838a tests: Test date overflow failure with bookmark file parsing
This is exactly the test case from oss-fuzz which triggers a negative
overflow when constructing dates.

oss-fuzz#22758

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-01 11:50:47 +01:00
Philip Withnall
19e242d1d5 gdatetime: Avoid integer overflow creating dates too far in the past
oss-fuzz#22758

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-01 11:50:47 +01:00
Sebastian Dröge
6f4680284c Merge branch 'backport-1644-winhttp-file-display-name-glib-2-64' into 'glib-2-64'
Backport !1644 “gwinhttpfile: Set display-name attribute on file info” to glib-2-64

See merge request GNOME/glib!1646
2020-10-01 10:30:21 +00:00
Sebastian Dröge
6711f7d2f4 Merge branch 'backport-1665-win32-module-glib-2-64' into 'glib-2-64'
Backport !1665 “Fix g_module_symbol() under Windows sometimes not succeeding” to glib-2-64

See merge request GNOME/glib!1666
2020-10-01 06:02:37 +00:00
Sebastian Dröge
1bb51ad023 Merge branch 'backport-1664-resolver-sign-glib-2-64' into 'glib-2-64'
Backport !1664 “gthreadedresolver: Fix logic in parse_res_text()” to glib-2-64

See merge request GNOME/glib!1668
2020-10-01 06:02:17 +00:00
Peter Bloomfield
9ded33cf59 gthreadedresolver: Fix logic in parse_res_text()
and avoid a sign-compare warning.

Fixes #2209
2020-09-30 16:45:57 +01:00
Christoph Reiter
0d3ba09072 Fix g_module_symbol() under Windows sometimes not succeeding
g_module_symbol() internally calls CreateToolhelp32Snapshot() which
in some circumstances returns ERROR_BAD_LENGTH and according to the docs
should lead to CreateToolhelp32Snapshot() being retried by the caller.

This retry logic was missing and for example led to g_module_symbol()
not succeeding if another thread happened to call the wrong function
at the wrong time.

This got noticed in the g-i build of gtk4 where g-i would call g_module_symbol()
on all gtk4 _get_type symbols and while inspecting the properties gtk4 would
spawn a thread calling SHGetSpecialFolderLocation() somewhere down the line.
During the call to SHGetSpecialFolderLocation() CreateToolhelp32Snapshot() would
return with ERROR_BAD_LENGTH for a short period of time and make g_module_symbol()
fail, which lead to "Invalid GType function" errors in g-i.

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/3213
2020-09-30 15:30:43 +01:00
Sebastian Dröge
629bf398a2 Merge branch 'backport-1187-msvc-arm32-glib-2-64' into 'glib-2-64'
Backport !1187 “Define G_MSVC_SYMBOL_PREFIX correctly for ARM32” to glib-2-64

See merge request GNOME/glib!1656
2020-09-23 10:45:32 +00:00
Sebastian Dröge
923b32ee08 Merge branch 'backport-1652-trash-portal-fix-glib-2-64' into 'glib-2-64'
Backport !1652 “trash portal: Handle portal failures” to glib-2-64

See merge request GNOME/glib!1659
2020-09-23 10:45:23 +00:00
Ryan Gonzalez
9cc200baa2 trash portal: Handle portal failures
Previously, only whether or not the D-Bus call itself succeeded was
checked, regardless of the result code from the actual trash operation.
2020-09-23 10:38:05 +01:00
Wolfgang Stöggl
c444a1aec7 Define G_MSVC_SYMBOL_PREFIX correctly for ARM32
Symbols on x86 are prefixed with an underscore
but symbols on x64/ARM/ARM64 are not.

Relevant information concerning the prefixes for the architectures
can be found in the vcpkg project [1,2], where arm and arm64 builds
are part of the CI.

Specifically, _WIN64 is defined on Windows ARM64, so this issue is
only visible when building on ARM32.

[1] 08e74979df/ports/glib/fix-arm-builds.patch
[2] https://github.com/microsoft/vcpkg/pull/6116
2020-09-22 12:51:19 +01:00
Juliano de Souza Camargo
82ed2f22de Update Portuguese translation 2020-09-21 14:05:44 +00:00
Philip Withnall
5993bd9509 gutf8: Fix a typo in the docs for g_utf16_to_utf8()
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-09-11 10:49:50 +01:00
Philip Withnall
bd99162d5c gwinhttpfile: Set display-name attribute on file info
It is not allowed to be `NULL` or unset if requested by the file
attribute matcher. Derive it from the basename. This doesn’t handle the
situation of a failed UTF-16 to UTF-8 conversion very well, but will at
least return something.

Note that the `g_filename_display_basename()` function can’t be used as
`GWinHttpFile` provides its URI in UTF-16 rather than in the file system
encoding.

This fixes a crash when using GIMP on Windows. Thanks to lillolollo for
in-depth debugging assistance.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #2194
2020-09-11 10:49:50 +01:00
Goran Vidović
814372482b Update Croatian translation 2020-09-05 22:05:47 +00:00
Sebastian Dröge
fba920af8f Merge branch 'backport-1632-fileutils-large-write-glib-2-64' into 'glib-2-64'
Backport !1632 Fix large writes in gfileutils to glib-2-64

See merge request GNOME/glib!1633
2020-09-03 09:33:46 +00:00
Sebastian Dröge
1659dd7a4d Merge branch 'backport-1631-splice-cancellation-glib-2-64' into 'glib-2-64'
Backport !1631 “Fix splice behavior on cancellation” to glib-2-64

See merge request GNOME/glib!1634
2020-09-03 09:33:40 +00:00
Carlos Garnacho
1b03204e67 tests: Add splice cancellation test
This doesn't trigger the cancellation assertion issue when run locally
(the task didn't return yet, so the error is simply overwritten), but
perhaps it ever does in CI. Anyhow, it's good to have a cancellation
test.
2020-09-01 11:56:24 +01:00
Carlos Garnacho
40865e0ba7 goutputstream: Check individual close operations after splice
After a splice operation is finished, it attempts to 1) close input/output
streams, as per the given flags, and 2) return the operation result (maybe
an error, too).

However, if the operation gets cancelled early and the streams indirectly
closed, the splice operation will try to close both descriptors and return
on the task when both are already closed. The catch here is that getting the
streams closed under its feet is possible, so the completion callback would
find both streams closed after returning on the first close operation and
return the error, but then the second operation could be able to trigger
a second error which would be returned as well.

What happens here is up to further race conditions, if the task didn't
return yet, the returned error will be simply replaced (but the old one not
freed...), if it did already return, it'll result in:

GLib-GIO-FATAL-CRITICAL: g_task_return_error: assertion '!task->ever_returned' failed

Fix this by flagging the close_async() callbacks, and checking that both
close operations did return, instead of checking that both streams are
closed by who knows.

This error triggers a semi-frequent CI failure in tracker, see the summary at
https://gitlab.gnome.org/GNOME/tracker/-/issues/240
2020-09-01 11:56:24 +01:00
Sebastian Dröge
259903ca53 Don't pass more than G_MAXSSIZE bytes at once to write() in glib/gfileutils.c
Behaviour in that case is implementation-defined and how many bytes were
actually written can't be expressed by the return value anymore.

Instead do a short write of G_MAXSSIZE bytes and let the existing loop
for handling short writes takes care of the remaining length.
2020-09-01 11:54:16 +01:00
Emmanuel Fleury
3ff911afaa Fixing signedness warning in glib/gfileutils.c
glib/gfileutils.c: In function ‘write_to_file’:
glib/gfileutils.c:1176:19: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’} [-Werror=sign-compare]
 1176 |       g_assert (s <= length);
      |                   ^~
glib/gmacros.h:939:25: note: in definition of macro ‘G_LIKELY’
  939 | #define G_LIKELY(expr) (expr)
      |                         ^~~~
glib/gfileutils.c:1176:7: note: in expansion of macro ‘g_assert’
 1176 |       g_assert (s <= length);
      |       ^~~~~~~~

Related to issue #1735 (Get back to a -werror build)
2020-09-01 11:54:16 +01:00
Philip Withnall
2560f61370 2.64.5
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2.64.5
2020-08-18 12:05:22 +01:00
Sebastian Dröge
b24969cefe Merge branch 'backport-1620-variant-depth-init-glib-2-64' into 'glib-2-64'
Backport !1620 “gvariant: Ensure GVS.depth is initialised” to glib-2-64

See merge request GNOME/glib!1621
2020-08-18 09:42:56 +00:00
Philip Withnall
2b6d4081e2 gvariant: Ensure GVS.depth is initialised
When byteswapping the depth was accidentally left uninitialised.

Coverity CID: #1430636
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-18 09:50:43 +01:00
Sebastian Dröge
03a53a9531 Merge branch 'backport-1617-subprocess-blocking-glib-2-64' into 'glib-2-64'
Backport !1617 “Ensure g_subprocess_communicate_async() never blocks” to glib-2-64

See merge request GNOME/glib!1618
2020-08-17 11:56:46 +00:00
Alexander Larsson
53c9497268 Ensure g_subprocess_communicate_async() never blocks
It turns out that our async write operation implementation is broken
on non-O_NONBLOCK pipes, because the default async write
implementation calls write() after poll() said there were some
space. However, the semantics of pipes is that unless O_NONBLOCK is set
then the write *will* block if the passed in write count is larger than
the available space.

This caused a deadlock in https://gitlab.gnome.org/GNOME/glib/-/issues/2182
due to the loop-back of the app stdout to the parent, but even without such
a deadlock it is a problem that we may block the mainloop at all.

In the particular case of g_subprocess_communicate() we have full
control of the pipes after starting the app, so it is safe to enable
O_NONBLOCK (i.e. we can ensure all the code using the fd after this can handle
non-blocking mode).

This fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2182
2020-08-17 12:25:45 +01:00
Sebastian Dröge
94ef46477c Merge branch 'backport-1607-ios-frexpl-glib-2-64' into 'glib-2-64'
Backport !1607 “meson: Don't use gnulib for printf on iOS” to glib-2-64

See merge request GNOME/glib!1608
2020-08-06 09:46:08 +00:00
Nirbheek Chauhan
41af1187c3 meson: Don't use gnulib for printf on iOS
iOS and tvOS use the same printf family as macOS, and these all have
been available on macOS for a long time.

Closes https://gitlab.gnome.org/GNOME/glib/-/issues/1868
2020-08-06 10:17:43 +01:00
Emmanuele Bassi
d2a232aee0 Merge branch 'backport-1563-desktop-app-info-leak-glib-2-64' into 'glib-2-64'
Backport !1563 “gdesktopappinfo: Fix unnecessarily copied and leaked URI list” to glib-2-64

See merge request GNOME/glib!1565
2020-07-06 11:44:06 +00:00
Felix Riemann
47cdc8e35a gdesktopappinfo: Fix unnecessarily copied and leaked URI list
When an app is spawned using g_desktop_app_info_launch_uris_with_spawn
it will expand the various token in the app's commandline with the
URIs of the files to open. The expand_macro() function that is used for
this advances the pointer to the URI list to show up to which entries
it used.

To not loose the pointer to the list head a duplicate of the URI list
was actually passed to expand_macro(). However, it's not necessary to
create a copy of the URI list for that as expand_macro() will only
change which element the pointer will point to.

This behaviour actually caused the duplicated list to be leaked as the
the list pointer is NULL once all URIs are used up by expand_macro()
and thus nothing was freed at the end of the function.
2020-07-06 11:58:47 +01:00
Sebastian Dröge
2cbd8717e2 Merge branch 'backport-1517-win32-registry-assertions' into 'glib-2-64'
Backport !1517 “GWin32RegistryKey: Move assertions” to glib-2-64

See merge request GNOME/glib!1520
2020-07-02 14:30:16 +00:00