Commit Graph

30186 Commits

Author SHA1 Message Date
Peter Bloomfield
8e29508d07 gstring: Make len_unsigned unsigned 2025-07-10 17:00:12 -05:00
Michael Catanzaro
28c379895e gstring: carefully handle gssize parameters
Wherever we use gssize to allow passing -1, we need to ensure we don't
overflow the value by assigning a gsize to it without checking if the
size exceeds the maximum gssize. The safest way to do this is to just
use normal gsize everywhere instead and use gssize only for the
parameter.

Our computers don't have enough RAM to write tests for this. I tried
forcing string->len to high values for test purposes, but this isn't
valid and will just cause out of bounds reads/writes due to
string->allocated_len being unexpectedly small, so I don't think we can
test this easily.
2025-07-10 17:00:11 -05:00
Michael Catanzaro
dd5d3f23b6 gsocks4aproxy: Fix a single byte buffer overflow in connect messages
`SOCKS4_CONN_MSG_LEN` failed to account for the length of the final nul
byte in the connect message, which is an addition in SOCKSv4a vs
SOCKSv4.

This means that the buffer for building and transmitting the connect
message could be overflowed if the username and hostname are both
`SOCKS4_MAX_LEN` (255) bytes long.

Proxy configurations are normally statically configured, so the username
is very unlikely to be near its maximum length, and hence this overflow
is unlikely to be triggered in practice.

(Commit message by Philip Withnall, diagnosis and fix by Michael
Catanzaro.)

Fixes: #3461
2025-07-10 17:00:10 -05:00
Simon McVittie
981cbf44b1 gdatetime test: Fall back if legacy System V PST8PDT is not available
On recent versions of Debian, PST8PDT is part of the tzdata-legacy
package, which is not always installed and might disappear in future.
Successfully tested with and without tzdata-legacy on Debian unstable.

Signed-off-by: Simon McVittie <smcv@debian.org>
2025-07-10 16:59:58 -05:00
Simon McVittie
cec3bdd847 gdatetime test: Try to make PST8PDT test more obviously correct
Instead of using timestamp 0 as a magic number (in this case interpreted
as 1970-01-01T00:00:00-08:00), calculate a timestamp from a recent
year/month/day in winter, in this case 2024-01-01T00:00:00-08:00.

Similarly, instead of using a timestamp 15 million seconds later
(1970-06-23T15:40:00-07:00), calculate a timestamp from a recent
year/month/day in summer, in this case 2024-07-01T00:00:00-07:00.

Signed-off-by: Simon McVittie <smcv@debian.org>
2025-07-10 16:59:51 -05:00
Rebecca N. Palmer
b6d3c5588d gdatetime test: Do not assume PST8PDT was always exactly -8/-7
In newer tzdata, it is an alias for America/Los_Angeles, which has a
slightly different meaning: DST did not exist there before 1883. As a
result, we can no longer hard-code the knowledge that interval 0 is
standard time and interval 1 is summer time, and instead we need to look
up the correct intervals from known timestamps.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3502
Bug-Debian: https://bugs.debian.org/1084190
[smcv: expand commit message, fix whitespace]
Signed-off-by: Simon McVittie <smcv@debian.org>
2025-07-10 16:59:44 -05:00
Ondrej Holy
0ee9a85509 gfile: Add support for x-gvfs-trash mount option
Currently, the trash functionality is disabled for system internal mounts.
That might be a problem in some cases. The `x-gvfs-notrash` mount option
allows disabling the trash functionality for certain mounts. Let's add
support for the `x-gvfs-trash` mount option to allow the opposite.

See: https://issues.redhat.com/browse/RHEL-46828
2025-07-10 16:59:35 -05:00
Michael Catanzaro
eb013cb5c3 Change default terminal to Ptyxis 2025-07-10 16:57:56 -05:00
Michael Catanzaro
c76bfa6e30 Disable MD5 and SHA-1 HMac tests
These are expected to be broken, depending on system crypto policy,
which may disable the algorithms.
2024-07-10 10:45:12 -05:00
Michael Catanzaro
678df1ffad dlopen GnuTLS instead of linking directly
I'd like to enable our GnuTLS GHmac patchset in Fedora in order to
ensure it is receiving sufficient real-world testing, since we've
discovered several bugs thus far. Problem is Fedora has one requirement
that RHEL does not: it needs to build glib as a static lib. This is
needed by QEMU in Fedora for complicated technical reasons that I don't
understand. However, nothing in RHEL needs it. This means we failed to
notice that glib2-static is broken in RHEL, because there is no
gnutls-static! We could fix this by adding a gnutls-static package, but
that seems like overkill, and adding more static libraries where they're
not truly necessary is not the direction we want to move in anyway. So
instead, let's just dlopen GnuTLS to sidestep this problem entirely.

This would not be a good solution for upstream, but upstream has made
clear that this patchset is already non-upstreamable, so it will be fine
for our purposes.
2024-07-10 10:43:29 -05:00
Colin Walters
6be9a415a7 Add a gnutls backend for GHmac
For RHEL we want apps to use FIPS-certified crypto libraries,
and HMAC apparently counts as "keyed" and hence needs to
be validated.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1630260
Replaces: https://gitlab.gnome.org/GNOME/glib/merge_requests/897

This is a build-time option that backs the GHmac API with GnuTLS.
Most distributors ship glib-networking built with GnuTLS, and
most apps use glib-networking, so this isn't a net-new library
in most cases.

=======================================================================

mcatanzaro note:

I've updated Colin's original patch with several enhancements:

Implement g_hmac_copy() using gnutls_hmac_copy(), which didn't exist
when Colin developed this patch.

Removed use of GSlice

Better error checking in g_hmac_new(). It is possible for
gnutls_hmac_init() to fail if running in FIPS mode and an MD5 digest is
requested. In this case, we should return NULL rather than returning a
broken GHmac with a NULL gnutls_hmac_hd_t. This was leading to a later
null pointer dereference inside gnutls_hmac_update(). Applications are
responsible for checking to ensure the return value of g_hmac_new() is
not NULL since it is annotated as nullable. Added documentation to
indicate this possibility.

Properly handle length -1 in g_hmac_update(). This means we've been
given a NUL-terminated string and should use strlen(). GnuTLS doesn't
accept -1, so let's call strlen() ourselves.

Crash the application with g_error() if gnutls_hmac() fails for any
reason. This is necessary because g_hmac_update() is not fallible, so we
have no way to indicate error. Crashing seems better than returning the
wrong result later when g_hmac_get_string() or g_hmac_get_digest() is
later called. (Those functions are also not fallible.) Fortunately, I
don't think this error should actually be hit in practice.

https://gitlab.gnome.org/GNOME/glib/-/merge_requests/903
2024-07-10 10:43:29 -05:00
Colin Walters
79c6d81cad ghmac: Split off wrapper functions into ghmac-utils.c
Prep for adding a GnuTLS HMAC implementation; these are just
utility functions that call the "core" API.
2024-07-10 10:43:29 -05:00
Philip Withnall
0e1647c0cb 2.80.4
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.80.4
2024-07-08 15:03:15 +01:00
Michael Catanzaro
3b22daf758 Merge branch 'backport-4110-dns-ref-glib-2-80' into 'glib-2-80'
Backport !4110 “gthreadedresolver: ref-sink returned records in lookup_records()” to glib-2-80

See merge request GNOME/glib!4141
2024-07-05 12:18:18 +00:00
Andy Holmes
bf7a270970 tests: ensure DNS records are full-reference variants
For each test expected to return valid DNS records, test that the
record variants are not floating references.

Also add an test which checks this explicitly for a simple TXT record.
2024-07-05 07:28:48 +01:00
Andy Holmes
b8aaa10a91 gthreadedresolver: ref-sink returned records in lookup_records()
The return value to `lookup_records()` methods is set as `transfer full`
but the code path in `g_resolver_records_from_res_query()` doesn't
sink the GVariant.

Add the `g_variant_ref_sink()` call when prepending the record, so
the list hold a full reference on each records.

closes #3393
2024-07-05 07:28:48 +01:00
Emmanuele Bassi
9b6af495cf Merge branch 'backport-4122-gir-deps-glib-2-80' into 'glib-2-80'
Backport !4020 and !4122: fixes to GIR install locations and build race fixes

See merge request GNOME/glib!4124
2024-06-27 09:55:02 +00:00
Philip Withnall
e8d11b0dbd introspection: Add libgirepository as a dep to all generate_gir() calls
libgirepository is not needed by most of the modules, but it is needed
by the `g-ir-scanner` generated dumper program. If we don’t explicitly
include the local version of it here, Meson will implicitly link against
it anyway, and that might pull in a different version, or try to link
against a half-built local version as the build ordering dependency tree
won’t reflect this relationship.

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

Fixes: #3401
2024-06-27 10:32:05 +01:00
Alexander Kanavin
1402132d63 girepository/introspection: correctly install .gir files into custom locations
There is a meson option (gir_dir_prefix), but without being passed in here
the files would always get installed into the default location (datadir).

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
2024-06-27 10:31:48 +01:00
Michael Catanzaro
5d70340412 Merge branch 'wip/pwithnall/backport-3373-file-load-4gb-glib-2-80' into 'glib-2-80'
Backport !3373 and !4117 “Handle files >4GB in g_file_load_contents()“ to glib-2-80

See merge request GNOME/glib!4118
2024-06-18 22:09:21 +00:00
Philip Withnall
b4085620c6 tests: Improve 4GB file loading test to work on i386
This should test the limits of loading 4GB files on i386 platforms, such
as the Hurd CI runner. On such platforms, `sizeof(size_t) == 4`.

This should fix the compiler warning from
https://gitlab.gnome.org/GNOME/glib/-/jobs/3989442:
```
../gio/tests/file.c:2931:51: error: left shift count >= width of type [-Werror=shift-count-overflow]
 2931 | static const gsize testfile_4gb_size = ((gsize) 1 << 32) + (1 << 16); /* 4GB + a bit */
      |                                                   ^~
cc1: all warnings being treated as errors
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-18 21:25:12 +01:00
Philip Withnall
724709f022 tests: Skip >4GB file tests unless running tests in slow/thorough mode
They take too long to include in a normal test run. They’ll still be run
in CI once a week as part of our scheduled slow test job.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-18 21:25:06 +01:00
Benjamin Otte
7ad4384af1 tests: Add test for >4GB reads with g_file_load_contents()
The tests - one for sync, one for async - create a sparse file for
this purpose, so this should be cheap on the fileystem.

Of course, the test still allocates >4GB of memory for the data that it
returns from g_file_load_contents(), I hope the CI test runners can deal
with that.
2024-06-18 21:24:39 +01:00
Benjamin Otte
84f3b1ab9e tests: Use g_clear_fd() 2024-06-18 21:24:39 +01:00
Benjamin Otte
c2b3a6c557 gfile: Rewrite load_contents() to use realloc()
GByteArray is limited to 4GB in size and the current code silently
overflows when that happens.

Replace both load_contents() and load_contents_async() implementations
with a version that uses realloc() and gsize to maintain the array.
2024-06-18 21:24:39 +01:00
Benjamin Otte
1cf39a3000 array: Abort on overflow
This is a precautionary assert that will probably only trigger on 32bit
OSes. But g_nearest_pow() can overflow.
2024-06-18 21:24:39 +01:00
Michael Catanzaro
e1d1c78fc8 Merge branch 'backport-4111-eaddrnotavail-macos-glib-2-80' into 'glib-2-80'
Backport !4111 “gioerror: Map EADDRNOTAVAIL to G_IO_ERROR_CONNECTION_REFUSED” to glib-2-80

See merge request GNOME/glib!4112
2024-06-13 20:55:47 +00:00
Philip Withnall
a2000e2b36 gioerror: Map EADDRNOTAVAIL to G_IO_ERROR_CONNECTION_REFUSED
Previously it was mapped (as a default) to `G_IO_ERROR_FAILED`.

It’s the error that macOS returns when trying to connect to a socket which
is bound but not listened to. Linux returns `ECONNREFUSED` in this case.
It’s helpful if they both map to the same `GIOError` value.

This should fix the `/socket-client/connection-fail` test on macOS,
which is currently
[failing](https://gitlab.gnome.org/GNOME/glib/-/jobs/3970547) with:
```
 # GLib-GIO-DEBUG: GSocketClient: Starting TCP connection attempt
 # GLib-GIO-DEBUG: GSocketClient: Connection attempt failed: Can't assign requested address
 # GLib-GIO-DEBUG: GSocketClient: Starting new address enumeration
 # GLib-GIO-DEBUG: GSocketClient: Address enumeration completed (out of addresses)
 # GLib-GIO-DEBUG: GSocketClient: Address enumeration failed: (null)
 # GLib-GIO-DEBUG: GSocketClient: Connection failed: Could not connect to localhost: Can't assign requested address
not ok /socket-client/connection-fail - GLib-GIO:ERROR:../gio/tests/gsocketclient-slow.c:231:test_connection_failed: assertion failed (local_error == (g-io-error-quark, 39)): Could not connect to localhost: Can't assign requested address (g-io-error-quark, 0)
Bail out!
```

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

See: #3184
Fixes: #3394
2024-06-13 20:59:43 +01:00
Philip Withnall
8f3ed07701 2.80.3
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.80.3
2024-06-10 12:22:09 +01:00
Emmanuele Bassi
14a26f969f Merge branch 'backport-4033-girepository-typelib-determinicity-glib-2-80' into 'glib-2-80'
Backport !4033 “girepository: Keep an ordered list of the loaded typelibs” to glib-2-80

See merge request GNOME/glib!4080
2024-06-10 10:27:29 +00:00
Jose Riha
0835b7df97 Update Slovak translation 2024-06-09 09:20:30 +00:00
Michael Catanzaro
c7f556596e Merge branch 'backport-4104-socket-client-leak-glib-2-80' into 'glib-2-80'
Backport !4104 “gsocketclient: Fix a leak of the task data on an error path” to glib-2-80

See merge request GNOME/glib!4105
2024-06-05 12:47:12 +00:00
Johan Sternerup
9fccda086a gsocketclient: Add unit test for leak of task data in error path
The unit test cover the error path that causes the leak described in
https://gitlab.gnome.org/GNOME/glib/-/issues/3184.
2024-06-05 12:57:59 +01:00
Philip Withnall
1942dd5b5c gsocketclient: Fix a leak of the task data on an error path
Once the task is completed (and `g_task_return_*()` has been called),
the task is no longer needed. It would make more sense to unref it in
`complete_connection_with_error()`, where `g_task_return_*()` is called,
but that complicates other call sites significantly, so I didn’t do it.

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

Fixes: #3184
2024-06-05 12:57:49 +01:00
Jordi Mas i Hernandez
0043895879 Update Catalan translation 2024-05-27 14:56:31 +00:00
Michael Catanzaro
197e2690ef Merge branch 'backport-4078-clang-discarded-qualifiers-glib-2-80' into 'glib-2-80'
Backport !4078 “tests: Fix clang compilation failure due to unrecognised option in pragma” to glib-2-80

See merge request GNOME/glib!4079
2024-05-16 23:59:09 +00:00
Philip Withnall
3858b8b815 girepository: Make gi_repository_get_loaded_namespaces() deterministic
As with the previous two commits, the results of calling
`gi_repository_get_loaded_namespaces()` were previously
non-deterministic due to being generated by iterating over a hash table,
which has a non-deterministic iteration order.

Fix that by using the new `ordered_typelibs` and `ordered_lazy_typelibs`
arrays to provide deterministic ordering.

At the same time, significantly reduce the number of allocations needed
to build the return value — previously the results would be built as a
linked list before being turned into an array. The linked list is now
banished to history.

Add some more unit tests to maximise test coverage of this method.

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

Fixes: #3303
2024-05-16 23:32:15 +01:00
Philip Withnall
400fac7c4a girepository: Make gi_repository_find_by_error_domain() deterministic
As with the previous commit, finding a `GIBaseInfo` matching the given
error domain was non-deterministic because it iterated through a hash
table of typelibs. Hash table iteration is non-deterministic.

Change the method to instead use the `ordered_typelibs` and
`ordered_lazy_typelibs` arrays to give deterministic iteration order.

Add a unit test, although it can’t test the interesting case of an error
domain which is present in both `GioUnix`/`GioWin32` and `Gio`, because
no such error domain exists.

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

Helps: #3303
2024-05-16 23:32:09 +01:00
Philip Withnall
48988a4098 girepository: Make gi_repository_find_by_gtype() deterministic
When faced with a `GType` which is present in multiple typelibs, the old
implementation was not deterministic, as it iterated over a hash table
of typelibs. The iteration order of a hash table is not deterministic.

Use the new `ordered_typelibs` and `ordered_lazy_typelibs` arrays to
iterate instead, making the order deterministic.

Add a unit test to check this. In particular, to check that symbols
which are present in both `Gio` and `GioUnix` are correctly resolved as
being from `GioUnix`.

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

Helps: #3303
2024-05-16 23:32:02 +01:00
Philip Withnall
25b7ecf895 gitypelib: Fix iterating through typelib prefixes
The iteration code used `g_string_overwrite_len()` to try and simplify
buffer allocation and growth, but seemingly forgot to handle the fact
that it doesn’t nul-terminate what it overwrites: the method is intended
to be used to splice bits into longer strings, not to overwrite an
entire nul-terminated string.

This meant that when iterating over a comma-separated `c_prefix` like
`GUnix,G`, on the second iteration `g_string_overwrite_len()` would be
used to write `G` into index 0 of the already-set `GUnix` string in the
buffer, leading to the first iteration happening all over again and the
`G` prefix being ignored.

This led to symbols failing to be matched to the `GioUnix` typelib, even
though they should have been.

This will be checked by a test in the following commit.

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

Helps: #3303
2024-05-16 23:31:56 +01:00
Philip Withnall
04bdf50c68 girepository: Fix a typo in a code comment
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 23:31:49 +01:00
Philip Withnall
7e3ec9a8ae girepository: Keep an ordered list of the loaded typelibs
There are various places where the set of typelibs is iterated over or
returned in an ordered way. In order to keep results deterministic and
reproducible, we need to keep this set ordered.

Keep a `GPtrArray` of the typelibs (one for fully-loaded ones and one
for lazy ones) alongside the existing hash tables. This will be used for
iteration in the next few commits.

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

Helps: #3303
2024-05-16 23:31:43 +01:00
Philip Withnall
c98805e5a1 ci: Temporarily run the FreeBSD on a schedule rather than every commit
The runner is currently offline and we can’t have that blocking
development.

See: https://gitlab.gnome.org/Infrastructure/Infrastructure/-/issues/1503

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 22:42:16 +01:00
Philip Withnall
7548b4865f tests: Fix clang compilation failure due to unrecognised option in pragma
Sigh.

```
../glib/tests/atomic.c:139:32: error: unknown warning group '-Wdiscarded-qualifiers', ignored [-Werror,-Wunknown-warning-option]
\#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
                               ^
1 error generated.
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 22:42:02 +01:00
Philip Withnall
2c379a35ba Merge branch 'backport-4065-girepository-bitfield-glib-2-80' into 'glib-2-80'
Backport !4065 “girepository: Don't assume a bitfield has a fixed size” to glib-2-80

See merge request GNOME/glib!4074
2024-05-16 21:38:28 +00:00
Emmanuele Bassi
2d60dc1539 Merge branch 'backport-4073-dbus-export-glib-2-80' into 'glib-2-80'
Backport !4073 “gmenuexporter: Fix a NULL pointer dereference on an error handling path” to glib-2-80

See merge request GNOME/glib!4077
2024-05-16 12:08:26 +00:00
Philip Withnall
043a06debb gactiongroupexporter: Fix memory problems on an error handling path
Almost identically to the previous commit, fix a similar latent bug in
`g_dbus_connection_export_action_group()`, which was not ready to handle
the fledgling `GActionGroupExporter` being freed early on an error
handling path.

See the previous commit message for details of the approach.

This includes a unit test.

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

Fixes: #3366
2024-05-16 12:20:07 +01:00
Philip Withnall
5f5667b2a0 gmenuexporter: Fix a NULL pointer dereference on an error handling path
This latent bug wasn’t triggered until commit 3f30ec86c (or its
cherry-pick onto `glib-2-80`, 747e3af99, which was first released in
2.80.1).

That change means that `g_menu_exporter_free()` is now called on the
registration failure path by `g_dbus_connection_register_object()`
before it returns. The caller then tries to call `g_slice_free()` on the
exporter again. The call to `g_menu_exporter_free()` tries to
dereference/free members of the exporter which it expects to be
initialised — but because this is happening in an error handling path,
they are not initialised.

If it were to get any further, the `g_slice_free()` would then be a
double-free on the exporter allocation.

Fix that by making `g_menu_exporter_free()` robust to some of the
exporter members being `NULL`, and moving some of the initialisation
code higher in `g_dbus_connection_export_menu_model()`, and removing the
duplicate free code on the error handling path.

This includes a unit test.

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

Fixes: #3366
2024-05-16 12:19:57 +01:00
Philip Withnall
c2ec54d641 Merge branch 'backport-4059-leak-fixes-glib-2-80' into 'glib-2-80'
Partially backport !4059 “tests: Fix various memory leaks and valgrind / ASAN errors” to glib-2-80

See merge request GNOME/glib!4070
2024-05-15 13:55:16 +00:00
Marco Trevisan (Treviño)
9c611f6ef9 glib/tests/mapping: Unref the mapped file on exit 2024-05-15 13:00:01 +01:00