31083 Commits

Author SHA1 Message Date
Philip Withnall
84bd676519
tests: Add a missing test for post-normalisation lowercasing in IDN
See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4387#note_2269324

This adds a test to increase the code coverage of `nameprep()` in
`ghostutils.c`. It was previously missing coverage of the second
`tolower()` operation. The new test triggers this by using a Unicode
codepoint which cannot be converted to lowercase itself, but which
normalises (NFKC) to uppercase characters which can — a Unicode Roman
numeral.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:27:22 +00:00
Philip Withnall
72ca779e36
tests: Use g_assert_*() rather than g_assert() in option-context tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:27:17 +00:00
Philip Withnall
a6c36498ed
ghostutils: Limit punycode decoding output length
It uses a `GArray` to build up the output, and the size of that is
limited to a `guint`, so add an assertion to make sure the code never
requests anything bigger.

Fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:27:11 +00:00
Philip Withnall
e35aa61a55
ghostutils: Clarify string ownership transfers
Rename the `tmp` variable to `name_owned` to make its purpose clearer,
and more consistently assign to both it and `name` and `len` (which is
the length of `name`) every time any of them are modified.

This should make the function `const`-correct without the need for
casts, and introduce no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:27:03 +00:00
Philip Withnall
91b491241e
ghostutils: Fix string length handling to use gssize
Rather than `gint`, which can overflow for long strings, although such
strings would probably have hit hostname length limits already.

This fixes a `-Wshorten-64-to-32` warning.

I looked at changing from `gssize` to `size_t` and handling the `len <
0` case with an explicit early call to `strlen()`, but it didn’t make
things simpler, as the code in `nameprep()` keeps changing the length of
the string as it processes it.

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

Helps: #3527
2025-02-06 12:26:59 +00:00
Philip Withnall
a5682aff2e
goption: Fix string length handling to use size_t type
When parsing command line options, use `size_t` to hold string lengths.
This introduces no functional changes (any strings long enough to fit in
`size_t` but not in `int` will probably hit command line length limits),
but it does fix a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:54 +00:00
Philip Withnall
4d49fc8222
goption: Move a variable declaration to the scopes where it’s used
This introduces no functional changes, it just splits the declaration of
`j` into three smaller-scoped declarations of the same type. This will
make the following commit clearer.

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

Helps: #3527
2025-02-06 12:26:50 +00:00
Philip Withnall
664aca14a5
goption: Add explicit int cast in integer parsing code
The code uses `strtol()` to parse an integer from a string, then
correctly verifies its range, then it did an implicit cast to `int` to
return the parsed integer. This causes a spurious `-Wshorten-64-to-32`
warning, so add an explicit cast to make the code’s intention clear.

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

Helps: #3527
2025-02-06 12:26:45 +00:00
Philip Withnall
63af851f15
goption: Fix string length storage to use size_t rather than int
This moves all the string length handling in this part of `goption.c` to
use `size_t`. However, we need to assert that the string length is
at most `G_MAXINT` later on, as the length is passed to `printf()` to
add indentation, and it only accepts `int` for that kind of placeholder.

This introduces no functional changes, but does fix some
`-Wshorten-64-to-32` warnings.

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

Helps: #3527
2025-02-06 12:26:41 +00:00
Philip Withnall
30c47b059c
glib-init: Fix type used for string length storage
This fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:36 +00:00
Philip Withnall
8c37608c0d
gpattern: Fix use of narrow types to contain string offsets
When parsing the pattern in `g_pattern_spec_new()`, the offsets of
wildcards and jokers were stored in a `gint`. This could overflow with
exceptionally long patterns.

Split the sign out into a separate boolean for `hw_pos` and `hj_pos`
(it’s not necessary for `tw_pos` or `tj_pos` because their sign was
never queried), and use `size_t` to correctly store string offsets.

Fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:29 +00:00
Philip Withnall
66f4a52bd6
grand: Add an explicit cast to silence a -Wshorten-64-to-32 warning
The seed is explicitly a `guint32`, so an implicit cast was already
happening. We don’t actually care if there’s a loss of precision here,
as it’s a pseudo-random seed value rather than an ordinal number, so add
an explicit cast to silence the warning.

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

Helps: #3527
2025-02-06 12:26:22 +00:00
Philip Withnall
b8e68db45b
grand: Fix return type for fread() call
This fixes a `-Wshorten-64-to-32` warning, but there’s no underlying bug
here, as the maximum requested read size is 4 bytes anyway.

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

Helps: #3527
2025-02-06 12:26:14 +00:00
Philip Withnall
49d8185d03
gscanner: Fix -Wshorten-64-to-32 warning when reading an integer token
There’s already a documented explicit cast here, so let’s add the
explicit cast in C to match that. Fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:00 +00:00
Philip Withnall
45a1c0fdc1
gscanner: Fix types for read() and lseek() function calls
Use the right-width types for arguments and return values from these
calls, so we don’t get `-Wshorten-64-to-32` warnings.

The `read()` calls can never return enough to overflow an `int` anyway,
as the requested buffer size is limited.

The `lseek()` call could potentially have a huge offset to span, but
only if the `GScanner` was operating on a huge file and somehow had its
pointers at opposite ends of the file. I have not investigated to see if
that is possible.

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

Helps: #3527
2024-11-07 14:52:33 +00:00
Philip Withnall
38d7e7e663
gmessages: Fix -Wshorten-64-to-32 warning with socklen_t
`socklen_t` is defined as an `int`, but we’re putting a `size_t` sized
value into it. Socket paths are guaranteed to fit in a `socklen_t`, so
it’s OK to cast down.

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

Helps: #3527
2024-11-07 13:19:25 +00:00
Philip Withnall
3edd005dab
gio-launch-desktop: Fix -Wshorten-64-to-32 warning with socklen_t
`socklen_t` is defined as an `int`, but we’re putting a `size_t` sized
value into it. Socket paths are guaranteed to fit in a `socklen_t`, so
it’s OK to cast down.

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

Helps: #3527
2024-11-07 13:15:23 +00:00
Philip Withnall
a429e56523
2.83.0
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.83.0
2024-11-06 14:20:19 +00:00
Philip Withnall
dbb42933f8 Merge branch 'faccessat-bsd' into 'main'
glocalfile: Disable faccessat()-based query_exists on FreeBSD

See merge request GNOME/glib!4366
2024-11-06 13:13:01 +00:00
Philip Withnall
7868e6dd33 Merge branch 'on-error-stack' into 'main'
Small improvements to g_on_error_stack_trace and g_on_error_query

See merge request GNOME/glib!4375
2024-11-06 12:30:09 +00:00
Philip Withnall
8e46f31a23 Merge branch 'thread-name-length' into 'main'
thread: Force-limit thread name length

See merge request GNOME/glib!4374
2024-11-06 12:15:56 +00:00
Matthias Clasen
904be498c5 Small improvements to g_on_error_query
We can do the [S] option even if g_prgname isn't set, now that
g_on_error_stack_trace(NULL) works.
2024-11-06 11:46:53 +00:00
Matthias Clasen
f6e71c25ed Small improvements to g_on_error_stack_trace
Make the gdb commands match what /usr/bin/gstack uses,
and produce a stacktrace including all threads.
2024-11-06 11:46:53 +00:00
Matthias Clasen
95cdd0f06f Small improvements to g_on_error_stack_trace
Make g_on_error_stack_trace (NULL) work by using /proc/$PID/exe.

This matches what /usr/bin/gstack does.
2024-11-06 11:46:53 +00:00
Matthias Clasen
5b84636e62 thread: Force-limit thread name length
The documentation for glibc's pthread_setname_np states:

    The thread name is a meaningful C language string,
    whose length is restricted to 16 characters,
    including the  terminating  null  byte  ('\0').

The documentation for Solaris' pthread_setname_np states:

    The thread name is a string of length 31 bytes or less,
    UTF-8 encoded.

Failing to respect this length limitation may lead to no name being
set, which is confusing, since the thread then shows up under the
binary name in gdb. This was happening for the pango worker thread
with the name "[pango] fontconfig".
2024-11-06 11:44:49 +00:00
Philip Withnall
9949067a69 Merge branch 'fix-gtask-auto-set-name-doc' into 'main'
gtask: Fix comment for auto task naming via 'g_task_set_source_tag()'

See merge request GNOME/glib!4383
2024-11-06 11:34:09 +00:00
Sid
9e29968183 gtask: Fix comment for auto task naming via 'g_task_set_source_tag()' 2024-11-06 11:34:09 +00:00
Philip Withnall
705832f269 Merge branch 'amolenaar/fix-content-typo' into 'main'
macos: Remove extraneous space from type identifier

See merge request GNOME/glib!4373
2024-11-04 17:02:22 +00:00
Arjan Molenaar
6cb13b153c macos: Remove extraous space from type identifier 2024-11-04 16:31:36 +00:00
Emmanuele Bassi
7abfef8e06 Merge branch 'wip/pwithnall/fix-unix-mounts-tests-deprecations' into 'main'
tests: Fix calls to deprecated API in unix-mounts tests

See merge request GNOME/glib!4367
2024-11-04 16:27:12 +00:00
Philip Withnall
a33f26ff58 Merge branch 'wip/gvariant-builder-init-unset' into 'main'
gvariant: Introduce G_VARIANT_BUILDER_INIT_UNSET

See merge request GNOME/glib!4377
2024-11-04 16:11:52 +00:00
Sebastian Wick
3f71e403ed gvariant: Introduce G_VARIANT_BUILDER_INIT_UNSET
For g_auto(GVariantBuilder) one needs to initialize it before the
function returns, so it's best to do it when the variable is declared.
G_VARIANT_BUILDER_INIT exists but requires specifying a GVariantType in
the declaration which moves the type away from the usage of the builder
which often results in less readable code. G_VARIANT_BUILDER_INIT also
mentions that it's possible to explicitly zero the variable but this is
hard to find and writing `g_auto(GVariantBuilder) builder = {0,};` is
kind of ugly.

This introduces G_VARIANT_BUILDER_INIT_UNSET which zero initializes the
variable being declared. This gives us documentation and hides the
explicitly zeroing detail:

  auto(GVariantBuilder) builder = G_VARIANT_BUILDER_INIT_UNSET ();
2024-11-04 16:43:42 +01:00
Sebastian Wick
b10a4507a5 gvariant: Use gi-docgen for the G_VARIANT_BUILDER_INIT documentation 2024-11-04 16:38:05 +01:00
Michael Catanzaro
155810edd9 Merge branch 'cm/fix-gio-tools-leaks' into 'main'
gio: Fix GFileEnumerator leaks in gio tools

See merge request GNOME/glib!4378
2024-11-04 15:29:34 +00:00
correctmost
5b2da7ecb3 gio: Fix GFileEnumerator leaks in gio tools 2024-11-03 12:22:01 -05:00
Michael Catanzaro
3dcf1ea13d Merge branch 'nm-nl' into 'main'
Enable GNetworkMonitorNetlink on FreeBSD

See merge request GNOME/glib!4376
2024-10-29 19:26:59 +00:00
Gleb Popov
02172bda73 Enable GNetworkMonitorNetlink on FreeBSD 2024-10-29 21:18:36 +03:00
Philip Withnall
0828714bd4 Merge branch 'structured-logging-domain-check-without-nul' into 'main'
glib: Don't require GLIB_DOMAIN to be a NUL-terminated string

See merge request GNOME/glib!4350
2024-10-24 20:41:32 +00:00
Philip Withnall
b0943a70e7 Merge branch 'issue_3512' into 'main'
glib/glib-private: Build glib without ASAN sanitizer on AIX.

Closes #3512

See merge request GNOME/glib!4368
2024-10-24 20:21:45 +00:00
Parth Patel
929114fad2 glib/glib-private: Build glib without ASAN sanitizer on AIX.
In AIX, we doesn't have lsan sysmbols related to sanitizer.
So, skipping this check in AIX to build glib without ASAN sanitizer.

Issue: https://gitlab.gnome.org/GNOME/glib/-/issues/3512
2024-10-23 11:10:32 -05:00
Philip Withnall
4c3f06acbf Merge branch 'str-is-ascii-ifunc' into 'main'
gutf8: Add ifunc resolver for g_str_is_ascii() too

Closes #3511

See merge request GNOME/glib!4364
2024-10-22 17:37:32 +00:00
Sebastian Dröge
99bf0c966a glib: Add test for handling of non-NUL terminated strings in default log handler 2024-10-22 19:08:25 +03:00
Sebastian Dröge
9719853507 glib: Make sure GLIB_OLD_LOG_API is a NUL-terminated string
Every usage in GLib ensures this but theoretically external code might
pass something else. As this is only meant to be used internally from
GLib, don't support the other case but at least avoid potential out of
bound reads.
2024-10-22 19:08:25 +03:00
Sebastian Dröge
f221864d6e glib: Don't require GLIB_DOMAIN to be a NUL-terminated string
The length might be passed explicitly in the field instead, and the
string might not have a NUL-terminator as happens for example when
passed from the Rust bindings.

This might lead to out of bounds reads.

Thanks to Sebastian Wiesner for noticing this.
2024-10-22 19:08:25 +03:00
Michael Catanzaro
2c345bd8e2 Merge branch 'fuzz-fix' into 'main'
fuzzing: Fix buffer overread error in the fuzz test itself

See merge request GNOME/glib!4365
2024-10-22 16:00:36 +00:00
Michael Catanzaro
155d00a61e Merge branch '3470-unicode-16' into 'main'
Update to Unicode 16.0.0 and fix Unicode composition for its new codepoints

Closes #3470

See merge request GNOME/glib!4362
2024-10-22 15:29:42 +00:00
Philip Withnall
c14810e08f
tests: Fix calls to deprecated API in unix-mounts tests
This fixes commit aac56f1618aabfcf4c6b3ef1ee5b87322208e9ad — I missed
this while reviewing it, but the unit tests were partially changed to
call the new APIs, without being fully changed. This caused the build to
succeed on Linux, but fail on macOS due to using a deprecated API.

Actually, a better approach for the unit tests would be to consistently
call the *old* APIs, as they all immediately call the new APIs. Then we
get coverage of both old and new for free, at the cost of putting
`G_GNUC_BEGIN_IGNORE_DEPRECATIONS` at the top of the test file.

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

Helps: #3492
2024-10-22 16:15:18 +01:00
Philip Withnall
e795c715b5 Merge branch 'fix-namespace-UnixMountEntry' into 'main'
UnixMountEntry: Deprecate g_unix_mount_* API in favor of g_unix_mount_entry_* API for GUnixMountEntry methods

Closes #3492

See merge request GNOME/glib!4337
2024-10-22 14:48:12 +00:00
Jialu Zhou
aac56f1618 UnixMountEntry: Deprecate g_unix_mount_* API in favor of g_unix_mount_entry_*
This issue arises because the g_unix_mount_* naming convention does not match
the GUnixMountEntry instance type, confusing the introspection generator.

To resolve this, we are deprecating the g_unix_mount_* API functions that take
a GUnixMountEntry parameter and introducing equivalent g_unix_mount_entry_*
functions that correctly associate with the GUnixMountEntry instance. This change
ensures that introspection data correctly treats these as instance methods and
that documentation reflects proper ownership of returned data.

(Some minor tweaks by Philip Withnall.)

Fixes: #3492
2024-10-22 15:31:52 +01:00
Philip Withnall
ad67d4e833
glocalfile: Disable faccessat()-based query_exists on FreeBSD
It appears not to work, and nobody interested in FreeBSD has picked it
up to investigate yet.

Rather than have a completely broken implementation of
`g_file_query_exists()` on FreeBSD, let’s settle for using the old one.
It’s slightly slower than the new one, but has worked fine for people
for years.

This essentially reverts commit 65ad41d8a473b4d47f1e470013caff93d50791d8
on FreeBSD. This commit can be reverted when a FreeBSD person
investigates what’s going wrong with the `faccessat()`-based
implementation.

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

Helps: #3495
2024-10-22 13:37:55 +01:00