26121 Commits

Author SHA1 Message Date
Philip Withnall
019505a7cc tests: Disable some random instance tests of GVariants
Building a `GVariant` using entirely random data may result in a
non-normally-formed `GVariant`. It’s always possible to read these
`GVariant`s, but the API might return default values for some or all of
their components.

In particular, this can easily happen when randomly generating the
offset tables for non-fixed-width container types.

If it does happen, bytewise comparison of the parsed `GVariant` with the
original bytes will not always match. So skip those checks.

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

Helps: #2121
2022-12-13 19:01:00 +00:00
Philip Withnall
8c1a7815e7 tests: Add another test for overlapping offsets in GVariant
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #2121
2022-12-13 19:01:00 +00:00
Philip Withnall
a6cb880af0 gvariant: Track checked and ordered offsets independently
The past few commits introduced the concept of known-good offsets in the
offset table (which is used for variable-width arrays and tuples).
Good offsets are ones which are non-overlapping with all the previous
offsets in the table.

If a bad offset is encountered when indexing into the array or tuple,
the cached known-good offset index will not be increased. In this way,
all child variants at and beyond the first bad offset can be returned as
default values rather than dereferencing potentially invalid data.

In this case, there was no information about the fact that the indexes
between the highest known-good index and the requested one had been
checked already. That could lead to a pathological case where an offset
table with an invalid first offset is repeatedly checked in full when
trying to access higher-indexed children.

Avoid that by storing the index of the highest checked offset in the
table, as well as the index of the highest good/ordered offset.

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

Helps: #2121
2022-12-13 19:01:00 +00:00
Philip Withnall
2d55b3b74b gvariant: Don’t allow child elements of a tuple to overlap each other
This is similar to the earlier commit which prevents child elements of a
variable-sized array from overlapping each other, but this time for
tuples. It is based heavily on ideas by William Manley.

Tuples are slightly different from variable-sized arrays in that they
contain a mixture of fixed and variable sized elements. All but one of
the variable sized elements have an entry in the frame offsets table.
This means that if we were to just check the ordering of the frame
offsets table, the variable sized elements could still overlap
interleaving fixed sized elements, which would be bad.

Therefore we have to check the elements rather than the frame offsets.

The logic of checking the elements up to the index currently being
requested, and caching the result in `ordered_offsets_up_to`, means that
the algorithmic cost implications are the same for this commit as for
variable-sized arrays: an O(N) cost for these checks is amortised out
over N accesses to O(1) per access.

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

Fixes: #2121
2022-12-13 19:01:00 +00:00
Philip Withnall
a62a6b5d3e gvariant-serialiser: Rework child size calculation
This reduces a few duplicate calls to `g_variant_type_info_query()` and
explains why they’re needed.

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

Helps: #2121
2022-12-13 19:01:00 +00:00
Philip Withnall
66e7c10aa1 gvariant-serialiser: Factor out code to get bounds of a tuple member
This introduces no functional changes.

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

Helps: #2121
2022-12-13 19:01:00 +00:00
William Manley
c8067857f7 gvariant: Don’t allow child elements to overlap with each other
If different elements of a variable sized array can overlap with each
other then we can cause a `GVariant` to normalise to a much larger type.

This commit changes the behaviour of `GVariant` with non-normal form data. If
an invalid frame offset is found all subsequent elements are given their
default value.

When retrieving an element at index `n` we scan the frame offsets up to index
`n` and if they are not in order we return an element with the default value
for that type.  This guarantees that elements don't overlap with each
other.  We remember the offset we've scanned up to so we don't need to
repeat this work on subsequent accesses.  We skip these checks for trusted
data.

Unfortunately this makes random access of untrusted data O(n) — at least
on first access.  It doesn't affect the algorithmic complexity of accessing
elements in order, such as when using the `GVariantIter` interface.  Also:
the cost of validation will be amortised as the `GVariant` instance is
continued to be used.

I've implemented this with 4 different functions, 1 for each element size,
rather than looping calling `gvs_read_unaligned_le` in the hope that the
compiler will find it easy to optimise and should produce fairly tight
code.

Fixes: #2121
2022-12-13 19:01:00 +00:00
Philip Withnall
5c27f22aff gvariant: Zero-initialise various GVariantSerialised objects
The following few commits will add a couple of new fields to
`GVariantSerialised`, and they should be zero-filled by default.

Try and pre-empt that a bit by zero-filling `GVariantSerialised` by
default in a few places.

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

Helps: #2121
2022-12-13 19:01:00 +00:00
William Manley
f8f5d8eefa gvariant-serialiser: Factor out functions for dealing with framing offsets
This introduces no functional changes.

Helps: #2121
2022-12-13 19:01:00 +00:00
William Manley
590f7a6b76 gvariant-core: Consolidate construction of GVariantSerialised
So I only need to change it in one place.

This introduces no functional changes.

Helps: #2121
2022-12-13 19:01:00 +00:00
Ekaterine Papava
145cfe1e5f Update Georgian translation 2022-12-13 06:06:54 +00:00
Olga Smirnova
17672aeb4d Add Interlingue translation 2022-12-12 00:15:54 +00:00
Philip Withnall
28ba667276 tests: Add basic GApplicationCommandLine unit tests
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-08 14:46:47 +00:00
Philip Withnall
a6a847abab gapplication: Validate types of well-known platform data keys
The platform data comes from the parent process, which should normally
be considered trusted (if we don’t trust it, it can do all sorts of
other things to mess this process up, such as setting
`LD_LIBRARY_PATH`).

However, it can also come from any process which calls `CommandLine`
over D-Bus, so always has to be able to handle untrusted input. In
particular, `v`-typed `GVariant`s must always have their dynamic type
validated before having values of a static type retrieved from them.

Includes unit tests.

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

Helps: #1904
2022-12-08 14:46:47 +00:00
Philip Withnall
04b685ce27 gapplication: Document that command line options must be validated
They come from an external process, so they must be validated.

In particular, it’s always easy to forget to validate the type of a
`GVariant`, and just try to get the stored value using a well-known
type; but that’s a programming error if the `GVariant` actually stores a
different type. Always check the variant type first if loading from a
`v`.

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

Helps: #1904
2022-12-08 14:46:47 +00:00
Philip Withnall
32c1437a20 gfdonotificationbackend: Validate actions before activating them
These actions are activated as a result of receiving the `ActionInvoked`
signal from `org.freedesktop.Notifications`. As that’s received from
another process over D-Bus, it’s feasible that it could be malformed.
Without validating the action and its parameter, assertions will be hit
within the `GAction` code.

While we should be able to trust whatever process owns
`org.freedesktop.Notifications`, it’s possible that’s not the case, so
best validate what we receive.

Includes unit tests.

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

Helps: #1904
2022-12-08 14:46:47 +00:00
Philip Withnall
8be263c39d tests: Add stub tests for GFdoNotificationBackend
This test is fairly pointless, but puts the infrastructure in place for
adding more tests for `GFdoNotificationBackend` in upcoming commits.

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

Helps: #1904
2022-12-08 14:46:47 +00:00
Philip Withnall
e056220762 gfdonotificationbackend: Don’t remove notification if invoking action fails
Invoking an action on a notification should remove it (by default,
unless the `resident` hint is set, but GLib doesn’t currently support
that).

If, somehow, an invalid action is invoked on the notification, that
shouldn’t cause it to be removed though, because no action has taken
place. So change the code to do that.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-08 14:35:25 +00:00
Philip Withnall
07cd35a657 gapplication: Validate actions activated over D-Bus
As with the previous commit, the arguments to `ActivateAction` have to
be validated before being passed to `g_action_group_activate_action()`.
As they come over D-Bus, they are coming from an untrusted source.

Includes unit tests for all D-Bus methods on `GApplication`.

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

Helps: #1904
2022-12-08 14:35:25 +00:00
Philip Withnall
58cf769033 gactiongroupexporter: Validate actions activated or changed over D-Bus
The action name, parameter and new state are all controlled by an
external process, so can’t be trusted. Ensure they are validated before
being passed to functions which assert that they are correctly typed and
extant.

Add unit tests.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Backport: cherry-picked to glib-2-74, and additional braces added to
  avoid a `-Wdeclaration-after-statement` warning not present on `main`
  because we’ve dropped that warning on `main`

Helps: #1904
2022-12-08 14:35:25 +00:00
Philip Withnall
583ed7a954 tests: Move a helper function around in the actions test
This will be used in an upcoming commit.

This introduces no functional changes.

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

Helps: #1904
2022-12-08 14:28:02 +00:00
Philip Withnall
9513b31b9e tests: Add some missing error checks to actions test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-08 14:27:58 +00:00
Philip Withnall
e5c00d29d4 tests: Stop using GMainLoop in actions test
Instead, iterate the `GMainContext` directly. This allows tests on
asynchronously returned values to be done in the actual test function,
rather than a callback, which should make the tests a little clearer.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-08 14:27:58 +00:00
Philip Withnall
9613412bb8 gtestdbus: Use g_timeout_add_seconds() rather than g_timeout_add()
This makes the code a little easier to understand and allows the kernel
a little bit more leeway in scheduling the callback, which is fine
because we don’t need high accuracy here.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-08 14:27:58 +00:00
Philip Withnall
74d1bd7b09 gnotificationbackend: Fix a GDBusConnection leak
`g_notification_backend_new_default()` adds a reference on
`backend->dbus_connection` (if non-`NULL`), but nothing ever unreffed
that.

Fix that by adding a dispose method.

In practice this is not really a problem, because the notification
backend is held alive by a `GApplication`, which lives as long as the
process. It’ll be a problem if someone is to ever add unit tests for
`GNotificationBackend`s though. So let’s fix it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-08 14:27:58 +00:00
Philip Withnall
239ab99c46 gfdonotificationbackend: Improve internal docs around floating GVariants
The code is correct, but from a quick read-through it wasn’t entirely
clear to me how it handled floating `GVariant`s in object state or the
`parameter` argument.

Add an assertion and some comments to hopefully clarify things a little.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-08 14:27:58 +00:00
Nart Tlisha
049103370c Update Abkhazian translation 2022-12-02 10:33:24 +00:00
Philip Withnall
a8ad6347a4
2.74.2
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.74.3
2022-12-01 14:03:47 +00:00
Simon McVittie
60d1ebbd2b Merge branch 'backport-3094-str-equal-cxx-glib-2-74' into 'glib-2-74'
Backport !3094 “gstrfuncs: Fix regression in C++ types accepted by g_str_equal()” to glib-2-74

See merge request GNOME/glib!3096
2022-11-30 13:46:05 +00:00
Philip Withnall
560e56fa71 gstrfuncs: Fix regression in C++ types accepted by g_str_equal()
Further to commit bcd364afef984da894045, fix the types accepted by the
`g_str_equal()` macro for C++ too. C++ is more restrictive about
const-correctness.

Add unit tests.

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

Fixes: #2820
2022-11-29 12:02:29 +00:00
Philip Withnall
b5299ed205
2.74.2
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.74.2
2022-11-24 12:29:05 +00:00
Emmanuele Bassi
7908532046 Merge branch 'backport-3061-variant-maybe-wrapper-speedup-glib-2-74' into 'glib-2-74'
Backport !3061 “gvariant-parser: Speed up maybe_wrapper() by an order of magnitude” to glib-2-74

See merge request GNOME/glib!3063
2022-11-24 11:33:56 +00:00
Marco Trevisan
c7aa6e3bf4 Merge branch 'backport-3082-str-equal-api-break-glib-2-74' into 'glib-2-74'
Backport !3082 “gstrfuncs: Fix regression in types accepted by g_str_equal()” to glib-2-74

See merge request GNOME/glib!3084
2022-11-22 17:10:08 +00:00
Philip Withnall
b46ed37c97 gstrfuncs: Fix regression in types accepted by g_str_equal()
The new macro form of `g_str_equal()` had stricter type checking than
the original function form. That would be nice, except it causes new
compiler warnings in third party projects, which counts as an API break
for us, so unfortunately we can’t do it.

Add some tests to prevent regressions on this again.

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

Fixes: #2809
2022-11-22 16:14:51 +00:00
Мирослав Николић
25df888507 Update Serbian translation 2022-11-20 14:27:19 +00:00
Philip Withnall
64c2f5f3bb gvariant-parser: Speed up maybe_wrapper() by an order of magnitude
This further helps with the potential denial of service problem in
issue #2782 / oss-fuzz#49462 / oss-fuzz#20177.

Instead of allocating a new `GVariant` for each nesting level of
maybe-types, allocate a single `GVariant` and give it the fully-nested
maybe type as its type. This has to be done in serialised form.

This prevents attackers from triggering O(size of container × typedecl
depth) allocations.

This is a follow up to commit 3e313438f1900a620485ba88aad64c4e857f6ad1,
and includes a test.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: #2782
oss-fuzz#20177
oss-fuzz#49462
2022-11-08 17:12:40 +00:00
Nathan Follens
5ee5900459 Update Dutch translation 2022-11-02 19:09:03 +00:00
Ray Strode
fcdf5ebd81 Merge branch 'open-pipe-revert-2-74-backport' into 'glib-2-74'
Backport !3029 “Revert "Handling collision between standard i/o file descriptors and newly created ones" ” to glib-2-74

See merge request GNOME/glib!3039
2022-11-02 16:08:00 +00:00
Ray Strode
1c1c452ff2 glib-unix: Add test to make sure g_unix_open_pipe will intrude standard range
Now that we know it's a bad idea to avoid the standard io fd range
when getting pipe fds for g_unix_open_pipe, we should test to make sure
we don't inadvertently try to do it again.

This commit adds that test.
2022-11-02 09:26:47 -04:00
Ray Strode
2a36bb4b7e Revert "Handling collision between standard i/o file descriptors and newly created ones"
g_unix_open_pipe tries to avoid the standard io fd range
when getting pipe fds. This turns out to be a bad idea because
certain buggy programs rely on it using that range.

This reverts commit d9ba6150909818beb05573f54f26232063492c5b

Closes: #2795
Reopens: #16
2022-11-02 09:26:45 -04:00
Michael Catanzaro
6870d08d4b Merge branch 'backport-3045-proxy-resolver-tagging-glib-2-74' into 'glib-2-74'
Backport !3045 “gproxyresolver: lookup_finish() should better parallel lookup_async()” to glib-2-74

See merge request GNOME/glib!3046
2022-11-02 13:06:43 +00:00
Michael Catanzaro
299812d5ec gproxyresolver: lookup_finish() should better parallel lookup_async()
In g_proxy_resolver_lookup_async() we have some error validation that
detects invalid URIs and directly returns an error, bypassing the
interface's lookup_async() function. This is great, but when the
interface's lookup_finish() function gets called later, it may assert
that the source tag of the GTask matches the interface's lookup_async()
function, which will not be the case.

As suggested by Philip, we need to check for this situation in
g_proxy_resolver_lookup_finish() and avoid calling into the interface
here if we did the same in g_proxy_resolver_lookup_async(). This can be
done by checking the source tag.

I added a few new tests to check the invalid URI "asdf" used in the
issue report. The final case, using async GProxyResolver directly,
checks for this bug.

Fixes #2799
2022-11-02 09:49:57 +00:00
Simon McVittie
05fdb2d049 Merge branch 'backport-3035-portal-header-guard-glib-2-74' into 'glib-2-74'
Backport !3035 “portal: Fix broken header guard” to glib-2-74

See merge request GNOME/glib!3038
2022-11-02 02:01:03 +00:00
Robert Ancell
1304f9ed92 portal: Fix broken header guard
This wouldn't have caused an issue with the current header contents, but could have triggered a future bug.
2022-10-31 12:32:22 +00:00
Nart Tlisha
681980d382 Update Abkhazian translation 2022-10-31 10:03:40 +00:00
Marco Trevisan
a1151bc166 Merge branch 'backport-3008-wrapped-argv-leak-glib-2-74' into 'glib-2-74'
Backport !3008 “gio/gdesktopappinfo: Free the wrapped argv array on launch failure” to glib-2-74

See merge request GNOME/glib!3017
2022-10-26 11:47:08 +00:00
Marco Trevisan (Treviño)
efb43ef813 gio/gdesktopappinfo: Free the wrapped argv array on launch failure
We create an array that we never free, ensure this is the case.
The previous commit gives CI a chance to check this with valgrind job.

Found as part of another review:
 - https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2839#note_1524922
2022-10-26 10:30:09 +01:00
Philip Withnall
058491cb6f 2.74.1
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2.74.1
2022-10-25 13:53:22 +01:00
Philip Withnall
8fa92cf69b Merge branch 'backport-3009-timezone-relative-link-target-glib-2-74' into 'glib-2-74'
Backport !3009 “gtimezone: Fix symlink checks on relative link targets” to glib-2-74

See merge request GNOME/glib!3010
2022-10-25 12:23:15 +00:00
Fabio Tomat
142f1712d2 Update Friulian translation 2022-10-25 11:43:10 +00:00