26055 Commits

Author SHA1 Message Date
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
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
Philip Withnall
14d5f25dd0 gfileutils: Mention possibility of relative paths in g_file_read_link()
It’s entirely possible that `g_file_read_link()` will return a relative
path. Mention that in the documentation, and include a short example of
how to make the path absolute for further computation.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-24 13:12:57 +01:00
Philip Withnall
0768067155 gtimezone: Fix symlink checks on relative link targets
The changes in 6265b2e6f70d6f0ec4d16adcdc5f7c53aecf0da4 to reject weird
`/etc/localtime` configurations where `/etc/localtime` links to another
symlink did not consider the case where the target of `/etc/localtime`
is a *relative* path. They only considered the case where the target is
absolute.

Relative paths are permissible in all symlinks. On my Fedora 36 system,
`/etc/localtime`’s target is `../usr/share/zoneinfo/Europe/London`.

Fix the check for toolbx by resolving relative paths before calling
`g_lstat()` on them.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-24 13:12:57 +01:00
Marco Trevisan
abac659264 Merge branch 'backport-2952-win32-test-fixes-glib-2-74' into 'glib-2-74'
Backport !2952 “Various win32 test fixes” to glib-2-74

See merge request GNOME/glib!2958
2022-10-21 16:02:36 +00:00
Marco Trevisan
957679f024 Merge branch 'backport-2947-gspawn-eintr-glib-2-74' into 'glib-2-74'
Backport !2947 “gspawn: avoid race due to retry with EINTR on close()” to glib-2-74

See merge request GNOME/glib!2988
2022-10-21 15:59:59 +00:00
Emmanuele Bassi
0e12b7d662 Merge branch 'backport-2934-floating-variants-grr-glib-2-74' into 'glib-2-74'
Backport !2934 “gobject: Always ref-sink variants in g_object_set” to glib-2-74

See merge request GNOME/glib!2998
2022-10-21 15:20:56 +00:00
Thomas Haller
7720c598f4 gspawn: use g_close()
g_close() now is async-signal-safe, as long as we don't request a GError
and pass a valid file descriptor.

Update "gspawn.c" to drop its safe_close() function and use
g_close() instead.
2022-10-21 15:38:27 +01:00
Thomas Haller
0cfc5b054a gstdio: make g_close() async-signal-safe under certain conditions
g_close() does something useful. It is not trivial to get EINTR handling of
close() right, in a portable manner. g_close() abstracts this.

We should allow glib users to use the function even in async-signal-safe
contexts, at least if the user heeds the caveat about GError and take care
not to fail assertions.

Backport 2.74: Modified to drop documentation changes to g_close() which
document its new async-signal-safe guarantees. They are not public
guarantees until 2.76. Also modified to include moving the code to
ignore `EINTR` from commit d5dc7d266f2b8d0f7d.
2022-10-21 15:37:33 +01:00
Matthias Clasen
fa8ca6e739 gobject: Always ref-sink variants in g_object_set
When collecting varargs, ignore the NOCOPY_CONTENTS
flag for variants. That is what our docs advice for
refcounted types, and it fixes a regression that
was inadvertendly introduced when we stopped doing
some extra GValue copies.

Includes a test case by Philip Withnall.

Fixes: #2774
2022-10-21 14:27:30 +01:00
Philip Withnall
ccc5dec3c0 Merge branch 'revert-2852-gobject-warnings-glib-2-74' into 'glib-2-74'
Revert "Replace most GObject warnings with criticals" on glib-2-74

See merge request GNOME/glib!2996
2022-10-21 13:09:43 +00:00
Philip Withnall
d38268c086 Merge branch 'wip/smcv/revert-2924' into 'glib-2-74'
Revert !2924 in 2.74.x branch

See merge request GNOME/glib!2995
2022-10-21 12:02:25 +00:00
Philip Withnall
b89e825cc1 Revert "Replace most GObject warnings with criticals"
This reverts commit 0ffe86a1f7e215e4561c3b9f1d03c3cd638ed00f.

This was intended to land for the 2.75.x unstable series, and not in the
2.74.x stable series.

Fixes: #2788
2022-10-21 12:51:00 +01:00
Simon McVittie
53178b084c Revert "Optimize g_double_hash implementation"
This reverts commit dd1f4f709ea8cad1a1d6184ee0883be128fb81d8.
which caused a regression on big-endian architectures (all doubles would
hash to zero).

Partially resolves #2787

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-21 10:25:13 +01:00
Simon McVittie
c8e9eaf9a3 Revert "Optional optimization for g_int64_hash"
This reverts commit c1af4b2b886bd77d6d8857cf3f677edbc0d34a61,
which caused a regression on big-endian architectures (all 64-bit
integers would hash to zero).

Partially resolves #2787

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-21 10:25:10 +01:00
Simon McVittie
f889275a28 Revert "Add tests for hash collisions in simple cases"
This reverts commit e02db8ea22d545749ecaf3be9d342cc565bc143a.
We can't guarantee a lack of hash collisions if we go back to the 2.74.0
hashing implementation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-21 10:25:07 +01:00
Marco Trevisan
f147c5eed1 Merge branch 'wip/pwithnall/backport-2978-osx-test-fixes-glib-2-74' into 'glib-2-74'
Backport !2978 “A couple of test fixes on OS X” to glib-2-74

See merge request GNOME/glib!2989
2022-10-20 16:26:10 +00:00
Ray Strode
428f6421fb tests: Check for public.text not text/plain on OSX
The "content type" on OSX is a Uniform Type Identifier not a MIME
type, so make sure to use the right format in the empty file test.
2022-10-20 13:53:09 +01:00