1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2026-10-24 00:49:00 +03:00

32960 Commits

Author SHA1 Message Date
Philip Withnall
802d1893cd 2.88.4
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.88.4
2026-10-08 11:42:12 +01:00
Michael Catanzaro
90f9a5cd2b Merge branch 'backport-5348-5349-5353-5355-5356-5357-5359-5360-5361-5362-5363-5375-5376-5388-security-fixes-glib-2-88' into 'glib-2-88'
Backport various security fixes to glib-2-88

See merge request GNOME/glib!5394
2026-10-07 14:53:24 -05:00
Philip Withnall
7a71141cc3 tests: Avoid a ubsan warning about passing NULL to strncmp()
The array data can be `NULL` if its length is zero.

This fixes the following CI failure:
```
322/425 glib:gio / socket-address                                              ERROR            0.08s   killed by signal 6 SIGABRT
――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
stderr:
../gio/tests/socket-address.c:201:19: runtime error: null pointer passed as argument 2, which is declared to never be null
/usr/include/string.h:160:33: note: nonnull attribute specified here
    #0 0x000000431715  (/builds/GNOME/glib/_build/gio/tests/socket-address+0x431715) (BuildId: 7c5e418267aa2008af8e77f4d04c31913e26aad7)
    #1 0x7fdabec8c862  (/builds/GNOME/glib/_build/glib/libglib-2.0.so.0+0x28c862) (BuildId: 12f0fded04a8c0437c073a267547f1cb487b1b1d)
    #2 0x7fdabec7e1b2  (/builds/GNOME/glib/_build/glib/libglib-2.0.so.0+0x27e1b2) (BuildId: 12f0fded04a8c0437c073a267547f1cb487b1b1d)
    #3 0x7fdabec7e533  (/builds/GNOME/glib/_build/glib/libglib-2.0.so.0+0x27e533) (BuildId: 12f0fded04a8c0437c073a267547f1cb487b1b1d)
    #4 0x7fdabec7e533  (/builds/GNOME/glib/_build/glib/libglib-2.0.so.0+0x27e533) (BuildId: 12f0fded04a8c0437c073a267547f1cb487b1b1d)
    #5 0x7fdabec7e533  (/builds/GNOME/glib/_build/glib/libglib-2.0.so.0+0x27e533) (BuildId: 12f0fded04a8c0437c073a267547f1cb487b1b1d)
    #6 0x7fdabec7bc89  (/builds/GNOME/glib/_build/glib/libglib-2.0.so.0+0x27bc89) (BuildId: 12f0fded04a8c0437c073a267547f1cb487b1b1d)
    #7 0x7fdabec7b785  (/builds/GNOME/glib/_build/glib/libglib-2.0.so.0+0x27b785) (BuildId: 12f0fded04a8c0437c073a267547f1cb487b1b1d)
    #8 0x00000042de31  (/builds/GNOME/glib/_build/gio/tests/socket-address+0x42de31) (BuildId: 7c5e418267aa2008af8e77f4d04c31913e26aad7)
    #9 0x7fdabd810447  (/lib64/libc.so.6+0x3447) (BuildId: dae6ae6929d69dca842288f5300af5a33d1bdcd7)
    #10 0x7fdabd81050a  (/lib64/libc.so.6+0x350a) (BuildId: dae6ae6929d69dca842288f5300af5a33d1bdcd7)
    #11 0x0000004015a4  (/builds/GNOME/glib/_build/gio/tests/socket-address+0x4015a4) (BuildId: 7c5e418267aa2008af8e77f4d04c31913e26aad7)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../gio/tests/socket-address.c:201:19
```

https://gitlab.gnome.org/GNOME/glib/-/jobs/7120334

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-10-06 23:09:02 +01:00
Benjamin Otte
39fc9d5357 socketaddress: Add check for new_from_native(x, TOO_BIG)
Test that if there are too many bytes passed in, the extra bytes
are ignored.
2026-10-06 23:08:40 +01:00
Benjamin Otte
c2814e7a36 socketaddress: Add a sanity check for clarity
G_STRUCT_OFFSET (struct sockaddr_un, sun_path) == sizeof (struct sockaddr)
should hold, and therefor the compiler should optimize it away, but it's
not required. So be clear and add it.
2026-10-06 23:08:40 +01:00
Benjamin Otte
6a59e007ec socketaddress: Ensure correct behavior for embedded nul
If g_socket_address_new_from_native (addr, sizeof (sockaddr_un)) gets
called, the size of the path will be UNIX_PATH_MAX even if it is
a null-terminated string.

Ensure that we return UNIX_PATH_MAX - 1 (because we force null
ternmination) as the path length in this case.
2026-10-06 23:08:40 +01:00
Benjamin Otte
c853db6486 socketaddress: Ensure non-nul-terminated paths work properly
When passing a filename of length UNIX_PATH_MAX via sockaddr_un it will
not be null-terminated. This will cause g_unix_socket_address_new() to
fail as it expects a null-terminated string.

Use g_unix_socket_address_new_with_type() instead as it allows passing a
length.

Testcase included.
2026-10-06 23:08:40 +01:00
Benjamin Otte
7e41a57659 unixsocketaddress: Allow full lengths for path addresses
Allow addresses of type G_UNIX_SOCKET_ADDRESS_PATH to be UNIX_PATH_MAX
characters long.

Previously they could only be UNIX_PATH_MAX - 1 characters long which
lead to an inconsistency with the UNIX APIs.

There is no implementation reason for this but correctness, where I
feared that AI exploit finders might find an exploit for this and wanted
to get ahead.

Testcase adapted for this usecase.
2026-10-06 23:08:40 +01:00
Benjamin Otte
8afee0ab18 unixsocketaddress: Ensure path length gets constructed properly
Ensure that no matter which way an address gets constructed, the path
length has the expected value.

Extensive testcase included.
2026-10-06 23:08:40 +01:00
Benjamin Otte
7f8c25086b fileutils: Check the mode before creating the file
... so we don't create a file with elevated permissions if not
necessary.

This avoids a potential race where a temporary file is created with
higher priviliges than the result, which is technically a data leak.

Fixes: 45a36e52b5
2026-10-06 23:07:54 +01:00
Matthias Clasen
0f0d7b7fab gresource: Avoid underflow
Resources are generally considered trusted data (after all,
they are typically part of the same binary). But we should
still be robust and avoid underflow if we can. When the data
is not compressed, we subtract 1 from the length of the data
to omit a trailing \0, without checking first if the length
of the data was zero. Don't do that to avoid underflow.

Tests included. The tests were produced and validated with
the help of AI.

Related: RHEL-215289
2026-10-06 23:07:31 +01:00
Matthias Clasen
6913f5eaee gmarkup: Be careful in error paths
g_markup_collect_attributes is running cleanup for all attributes,
even those that haven't been processed, because a failure happened
earlier. This is harmless if the out arguments are all
NULL-initialized, but could lead to a wild free if somebody
were to pass the address of an uninitialized pointer.

Tests included. The tests were developed and validated with
the help of AI.

Related: RHEL-221493
2026-10-06 23:07:16 +01:00
Matthias Clasen
943e2e9f30 unicode: Prevent overflow in normalization
_g_utf8_normalize_wc() performs a first pass to count the number of output
`gunichar` elements needed after decomposition, then allocates a buffer from
that count. On 32-bit builds, the unchecked additions into `n_wc` can wrap
before allocation. If that happens, the allocated buffer is too small
and overflow happens during the second pass. Prevent this by using
checked arithmetic where it matters.

Tests included which run only on 32-bit builds. The tests were
produced and validated with the help of AI.

Related: RHEL-216132
2026-10-06 23:07:00 +01:00
Matthias Clasen
a59038c963 unicode: Add overflow precondition checks for str + len
g_utf8_strup(), g_utf8_strdown() and g_utf8_casefold() compute
str + len when len is non-negative, which could overflow if str
is near the end of the address space. Add g_return_val_if_fail
checks to prevent this.

Related: RHEL-216604
2026-10-06 23:06:37 +01:00
Matthias Clasen
fc4ce44d74 unicode: Fix test_strupdown_length for Windows
On Windows, setlocale() alone is not sufficient for GLib to detect
locale-specific casing rules — SetThreadLocale() is also needed.
Add SetThreadLocale() calls for Turkish and Lithuanian locales,
matching the pattern used in test_turkish_strupdown.

Also drop the .UTF-8 suffix from locale names, since it is not
available on Windows.
2026-10-06 23:06:37 +01:00
Matthias Clasen
11037b4801 unicode: Don't read past limits
g_utf8_strdup and g_utf8_strdown take a len argument, but they
can be tricked into reading past that limit, e.g. when doing
lookahead for a combining dot, or when the text section before
the limit ends with a greek iota below (U+0345). Prevent this
by passing the limit to the helper functions that are used
in these cases (append_mark and has_more_above).

Tests included. The tests were produced and validated with
the help of AI.

Related: RHEL-216604
2026-10-06 23:06:37 +01:00
Matthias Clasen
7566c4d793 unicode: Fix error handling in normalization
g_utf8_normalize is supposed to return NULL for input that
is not valid UTF-8, but it will sometimes return a valid
prefix up to the first invalid characters.
Use g_utf8_get_char_validated to detect this and return
NULL, as expected.

Tests included. The test were produced and validated with
the help of AI.

Related: RHEL-214768
2026-10-06 23:06:04 +01:00
Benjamin Otte
b9e2d37880 logging: Don't stack overflow with too many fields
When too many fields are passed to g_log_writer_journald(), stop using
alloca() for the field arrays and instead use malloc().

This can in theory be exploited remotely via g_log_variant(), but glib
does not use this function.

Testcase included.
2026-10-06 23:03:59 +01:00
Benjamin Otte
7b91721bc9 gdbusauthmechanismsha1: Don't split into too many tokens
When we expect that splitting a string should result in N tokens, we
don't need to split into more than N+1 tokens before we know it's an
error.

This is a hardening suggestion from an AI tool.
2026-10-06 23:03:42 +01:00
Benjamin Otte
1f928ca406 rcbox: Turn assertion into error
The max size is not documented anywhere, so we should be more careful
when checking it and not allow non-assertion builds to skip the overflow
check.

This also brings the code in line with gmem.c which also uses g_error()
on overflows.

Tests included.
2026-10-06 23:03:19 +01:00
Benjamin Otte
4bc78eb353 gvariant: Handle get_data_as_bytes() for corrupted variants
When a GVariant was created from invalid data - in particular, from data
that is too small - then it cannot return that invalid data.

In that case, it should probably return NULL but because it is
documented as never returning NULL, we cannot do that. So return a new
GBytes with zeroed data instead.

Fixes efe5b70192
2026-10-06 23:02:59 +01:00
Benjamin Otte
85c22fc65f giochannel: Fix strncmp() off the end of the buffer
.. when the data is not utf-8 encoded.

Related: 9f557746c5
2026-10-06 23:02:34 +01:00
Philip Withnall
6d9cabe1ce Merge branch 'update-translation-nn-from-glib-2-88-60fc5380-b8eb-11f1-bfd2-0a580a8205d0' into 'glib-2-88'
Update Norwegian Nynorsk translation

See merge request GNOME/glib!5379
2026-09-26 16:41:24 +00:00
Roy-Magne Mo
6cc5d2c4a1 Update Norwegian Nynorsk translation 2026-09-25 14:14:34 +00:00
Emmanuele Bassi
3b5dbf99a5 Merge branch 'backport-5311-trash-utf8-glib-2-88' into 'glib-2-88'
Backport !5311 “fix: handle long filenames in trash by truncating from front” to glib-2-88

See merge request GNOME/glib!5323
2026-09-22 17:38:00 +01:00
Liu Zhangjian
311bedcb04 fix: handle long filenames in trash by truncating from front
The `g_local_file_trash` function previously truncated filenames from
the front
on a plain byte boundary when encountering `ENAMETOOLONG`. This could
produce
invalid UTF-8 filenames, causing garbled names in the trash for UTF-
8 locales.

A new helper `truncate_basename_front` is introduced that:
- Truncates from the front, preserving the trailing part (extension)
of the
  original name.
- For UTF-8 filenames, skips continuation bytes to align the cut to
a character
  boundary, ensuring the result remains valid UTF-8.
- For non-UTF-8 (single-byte or best-effort), falls back to a plain
byte cut.

The code now uses this helper in both the `".trashinfo"` suffix and
`".XXXXXX"`
template cases, removing the duplicated inline logic. The helper returns
0 if
the base name is too short to truncate safely, in which case the
original
`ENAMETOOLONG` error is preserved.
2026-08-26 10:09:40 +01:00
Emmanuele Bassi
fb43b26b26 Merge branch 'backport-5266-docs-url-glib-2-88' into 'glib-2-88'
Backport !5266 “docs: Fix gio gi-docgen docs_url” to glib-2-88

See merge request GNOME/glib!5273
2026-08-13 15:20:28 +01:00
Philip Withnall
0d176e50c0 Merge branch 'backport-mr-5283-to-glib-2-88' into 'glib-2-88'
Backport !5283 “gconstructor: Reference _tls_used also on GCC, CLang” to glib-2-88

See merge request GNOME/glib!5285
2026-08-07 17:49:36 +00:00
Luca Bacci
05028ab09d gconstructor: Reference _tls_used also on GCC, CLang
This is required after recent changes in mingw-w64-crt:
https://sourceforge.net/p/mingw-w64/mailman/message/59361062/

Fixes #4020
2026-08-07 18:17:22 +02:00
Philipp Jungkamp
67468d8fa8 docs: Fix gio gi-docgen docs_url 2026-08-03 10:36:49 +01:00
Simon McVittie
1403b2cbf3 Merge branch 'backport-5261-installed-service-file-glib-2-88' into 'glib-2-88'
Backport !5261 “gio/tests/services: Fix installed service file containing build path” to glib-2-88

See merge request GNOME/glib!5262
2026-07-31 12:15:37 +00:00
Jaipaul Cheernam
348ed57d6f gio/tests/services: Fix installed service file containing build path
The refactoring in !5259 changed the installed service file's
configure_file() to use the build output as input instead of the
original .in template. Since @installed_tests_dir@ is already
substituted in the build output, the installed version gets the
build directory path instead of the install prefix.

Use the .in template directly as input for the installed version.

Closes #4011
2026-07-31 12:03:30 +01:00
Philip Withnall
43bc79ea88 2.88.3
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.88.3
2026-07-29 14:17:36 +01:00
Emmanuele Bassi
a70d033974 Merge branch 'backport-5248-5249-meson-gcc-fixes-glib-2-88' into 'glib-2-88'
Backport !5248, !5249: several Meson/gcc fixes to glib-2-88

See merge request GNOME/glib!5259
2026-07-29 14:14:44 +01:00
Philip Withnall
480134598f build: Fix a deprecation warning from Meson 1.12
It warns that configured files must be referred to by reference rather
than by name, and that support for the latter will be dropped with Meson
2.0.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-07-29 13:49:49 +01:00
Philip Withnall
3f9dc13e37 build: Rename a Meson variable
This introduces no functional changes, but will simplify the following
commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-07-29 13:49:45 +01:00
Philip Withnall
e012f640c9 tests: Move a feature test macro definition
Feature test macros always need to be defined before any headers are
included. This triggers a redefinition warning with GCC 16 and the new
gnu11 C level.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-07-29 13:49:40 +01:00
Philip Withnall
41e4ba0d5a tests: Fix some const warnings
GCC 16 is a little better than before at detecting accidentally dropped
`const` modifiers.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-07-29 13:49:34 +01:00
Philip Withnall
c17e78fc44 Merge branch 'backport-5238-macos-poll-clear-glib-2-88' into 'glib-2-88'
Backport !5238 “gpoll: Correctly zero-out heap-allocated fd_sets on macOS” to glib-2-88

See merge request GNOME/glib!5242
2026-07-22 10:20:01 +00:00
Emmanuele Bassi
4e41751c76 Merge branch 'translatable-string-glib-2-88' into 'glib-2-88'
gdbusauth: Unmark a new string as translatable

See merge request GNOME/glib!5243
2026-07-10 16:40:39 +01:00
Philip Withnall
98930ba8d3 gdbusauth: Unmark a new string as translatable
In the backport commit 4235f7b42 a new string was accidentally added
which broke string freeze. Because it’s very unlikely this string will
be shown (it’s an error message only shown if running a custom D-Bus
server and it’s being attacked by a malicious client), just drop the
translation marker on this stable branch.

The string will get translated for the next stable release on `main`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: https://gitlab.gnome.org/Teams/Translation/Coordination/-/work_items/529
2026-07-10 16:07:41 +01:00
Emmanuele Bassi
c3a332fb2e Merge branch 'backport-5240-gdbus-auth-limiting-glib-2-88' into 'glib-2-88'
Backport !5240 “gdbusauth: Limit length of lines read from client” to glib-2-88

See merge request GNOME/glib!5241
2026-07-10 16:03:18 +01:00
Alex Kirszenberg
02689c1aae gpoll: Correctly zero-out heap-allocated fd_sets on macOS 2026-07-10 15:52:55 +01:00
Philip Withnall
4235f7b42b gdbusauth: Limit length of lines read from client
The client isn’t trusted at this point, and there was previously nothing
limiting how long a line `GDBusAuth` would read. So an untrusted client
could exhaust the server’s memory by sending anything except `\r\n`.

Fix that by applying a reasonably length limit when reading a line, and
add a unit test.

Spotted by Gitee Codepecker Lab.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: #3985
2026-07-10 15:37:32 +01:00
Marco Trevisan
ca46dff809 Merge branch 'backport-5223-const-shenanigans-glib-2-88' into 'glib-2-88'
Backport !5223 “Drop G_GNUC_CONST for *_get_type” to glib-2-88

See merge request GNOME/glib!5225
2026-07-04 13:59:31 +02:00
Philip Withnall
b7cea87cc4 codegen: Drop an inappropriate G_GNUC_CONST from inside a code comment
Might as well have this comment reflect reality (see the previous few
commits).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-06-25 18:07:04 +01:00
Philip Withnall
fc6e8e3b27 gquark: Fix an incorrect G_GNUC_CONST annotation on g_quark_to_string()
It’s actually `G_GNUC_PURE` as its return value depends on the global
quark table.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-06-25 18:02:00 +01:00
Sam James
5c2f36682a gtype: downgrade some (non-*_get_type) G_GNUC_CONST -> G_GNUC_PURE
g_type_check_is_value_type and g_type_test_flags both read global memory,
so can't be const. They only seem to write for the purpose of a lock, which
they undo at the end, so maybe we can get away with G_GNUC_PURE here.

Bug: https://gitlab.gnome.org/GNOME/glib/-/work_items/3984
Signed-off-by: Sam James <sam@gentoo.org>
2026-06-25 17:59:14 +01:00
Sam James
945953ed03 Drop G_GNUC_CONST for *_get_type
g_type_ensure has a large comment saying _get_type shouldn't be
marked with G_GNUC_CONST because it has side-effects on the first
run, but it's OK if you consistently call g_type_ensure first.

Unfortunately, this isn't accurate. GCC trunk (observed at r17-1725-ge259a182e1f100)
now analyses points-to information more effectively and propagates its
findings, so it sees the function modifies some global state, concludes
that can't be possible (because of the const attribute), and deletes
the stores.

pure unfortunately is unsuitable for *_get_type too as it has a side-effect
(writes to global memory).

Mesa had a similar issue which I fixed recently [0]. glib and glibmm likely
want the (not-yet-implemented) 'idempotent' attribute instead [1]. In fact,
this exact problem is what motivated that request! :)

ebassi mentions an alternative to the current setup as well, using
atomics [2].

This problem has gone back many years but the compiler has finally
fully outsmarted us here, so give in.

[0] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/42361
[1] https://gcc.gnu.org/PR32911
[2] https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4249#note_2583110

Fixes: https://gitlab.gnome.org/GNOME/glib/-/work_items/3984
Signed-off-by: Sam James <sam@gentoo.org>
2026-06-25 17:59:14 +01:00
Philip Withnall
07233788db 2.88.2
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.88.2
2026-06-25 14:35:18 +01:00