Commit Graph

31884 Commits

Author SHA1 Message Date
Kate Hsuan
94e6da0fca gio: gmemorymonitorbase: parent class of GMemoryMonitor backends
This class provides the shared functions, such as sending a signal and
string and value conversion. The backend classes should inherit this
class to get the shared functions.

It adds a configure time check for `sysinfo()`, as some systems don’t
have it.
2025-07-21 16:09:46 +01:00
Philip Withnall
1eabe6c6b1 Merge branch 'null_terminated_check' into 'main'
garray: Fix out of boundary write in g_ptr_array_copy

See merge request GNOME/glib!4690
2025-07-15 12:40:56 +00:00
Philip Withnall
582cf1da92 Merge branch 'docs-module-constructor-locks' into 'main'
docs: Calling gmodule funcs in constructors may deadlock

Closes #1443

See merge request GNOME/glib!4691
2025-07-15 11:18:27 +00:00
Nick Steel
267b1246d7 docs: Calling gmodule funcs in constructors may deadlock
Fixes #1443.
2025-07-15 11:18:27 +00:00
Tobias Stoeckmann
42cd9d7efa garray: Simplify null termination handling
Apply GArray's g_array_maybe_expand overflow checking logic to
GPtrArray's g_ptr_array_maybe_expand function:

Let g_ptr_array_maybe_expand handle the null_terminated flag internally
to check if an overflow occurs instead of letting callers do these
check on their own.

The g_ptr_array_copy function lacked this check.

Having a centralized position for this check simplifies the code and
further code auditings.
2025-07-14 18:19:54 +02:00
Tobias Stoeckmann
eaffbef760 garray: Fix size checks when taking arrays
The functions g_array_new_take_zero_terminated and
g_ptr_array_new_take_null_terminated must take into account that the
last element will be the terminating element (zero filled or NULL).

Iterating through all elements must not reach G_MAXUINT, because in
that case no space is left for the terminating element.
2025-07-14 17:40:02 +02:00
Philip Withnall
6e2a31f97a Merge branch 'vprintf_int' into 'main'
gstring: Fix g_string_append_vprintf overflow

See merge request GNOME/glib!4687
2025-07-12 15:04:08 +00:00
Philip Withnall
457ba21d28 Merge branch 'binary_search' into 'main'
garray: Use g_array_elt_len/pos where appropriate

See merge request GNOME/glib!4685
2025-07-12 15:01:15 +00:00
Philip Withnall
ec1fb920bd Merge branch 'zero_terminate_null' into 'main'
garray: Support unallocated zero terminated arrays

See merge request GNOME/glib!4684
2025-07-12 14:56:48 +00:00
Philip Withnall
e43ebf8e61 Merge branch 'gapplication-fixes' into 'main'
gapplication: Call before/after_emit consistently

Closes #3726

See merge request GNOME/glib!4688
2025-07-11 11:51:42 +00:00
Matthias Clasen
1bb48a76a6 application: Call before/after_emit consistently
Call these vfuncs also for cases where the launching instance
is the primary one. This is what the docs suggest, and it makes
before/after_emit much more useful.

Fixes: #3726
2025-07-11 07:33:02 -04:00
Matthias Clasen
182185e31e application: Clarify documentation
Existing uses of before_emit in GTK will break if an app overrides
before/after_emit without chaining up. Clarify in the documentation
that these vfuncs need to chain up.
2025-07-11 07:33:02 -04:00
Matthias Clasen
de85736791 tests: Remove an overzealous assertion
The dbus-appinfo test was asserting that before_emit only happens
when we haven't seen a startup ID yet. But the docs imply that it
gets emitted for every activate/open/commandline, which may well
happen repeatedly. So drop this assertion.
2025-07-11 07:33:02 -04:00
Tobias Stoeckmann
591e39dbe9 garray: Support unallocated zero terminated arrays
The g_array_new_take_zero_terminated function could lead to NULL
data pointer if it is called with (NULL, FALSE, x), i.e. with a NULL
pointer and no clear request.

This in turn means that g_array_steal could behave like
g_ptr_array_steal, i.e. it would return NULL instead of a zero
terminated array, which does not match its description.

Also, g_array_remove_range and g_array_set_size could lead to NULL
pointer dereferences with such arrays.

Support all these cases and adjust the API description to reflect
current behavior. It brings GArray and GPtrArray functionality closer
to each other without breaking existing API/ABI for programs.
2025-07-10 17:00:12 +02:00
Tobias Stoeckmann
1f06e086f3 gstring: Fix g_string_append_vprintf overflow
The g_string_append_vprintf function could overflow with strings
which are INT_MAX bytes long. The eventual memcpy call copies INT_MAX
plus additional nul byte into newly allocated memory. This means
that due to signed integer overflow more bytes are copied than
could ever fit.
2025-07-09 22:37:48 +02:00
Tobias Stoeckmann
ca1b2028fc garray: Use g_array_elt_len/pos where appropriate
The multiplication of two guint values could overflow with large
arrays. Use g_array_elt_len and g_array_elt_pos to avoid explicit
elt_size multiplications.
2025-07-09 20:28:21 +02:00
Philip Withnall
5da569a425 Merge branch 'pgriffis/ipv6-scope-id' into 'main'
Fix IPv6 scope-id from DNS responses being lost

See merge request GNOME/glib!4676
2025-07-09 14:00:18 +00:00
Philip Withnall
f560c7b792 Merge branch 'fix-k-field-code-expansion' into 'main'
gio-tool-launch: fix %k field code expansion

See merge request GNOME/glib!4682
2025-07-09 13:10:28 +00:00
Philip Withnall
5cff35b41e Merge branch 'source-destroy-while-callback-indirect-unref' into 'main'
gmain: move source destroy write unlock slightly earlier

Closes #3725

See merge request GNOME/glib!4686
2025-07-09 12:50:09 +00:00
Christoph Martin
e2970dad72 tests: skip gio launch tests on darwin
Tests currently fail under macOS because the tool claims not to work
on apple devices. Since I cannot disprove this myself, I'm disabling the
tests on Darwin.
2025-07-09 13:39:34 +01:00
Christoph Martin
c924de69f0 gio-tool-launch: fix %k field code expansion
As per the desktop entry specification, the `%k` field code should be
expanded to the location of the desktop entry file being processed. This
is only possible if the constructor-only filename property is populated,
which does not happen when using g_desktop_app_info_new_from_keyfile().

Moreover, since the Path directive in a desktop entry can be used to
set the working directory for the program to be launched, the location
passed as argument to the program must be modified such that it points
at the correct file when interpreted by the launched program. The
simplest way to achieve this consistently is to pass an absolute path.

However, g_desktop_app_info_new_from_keyfile() does not indicate why it
fails when it does. Because the tool aims to indicate whether launching
failed due to a missing file or a malformed one we first check this with
g_key_file_load_from_file().
2025-07-09 13:39:34 +01:00
Christoph Martin
c2debf4fa9 tests: ensure gio launch expands field code %k
This introduces an integration test that executes gio launch from a
variety of working directories, and checks that %k is expanded to a
location that makes sense in the context of the executed program, i.e.
an absolute path.
2025-07-09 13:39:34 +01:00
Matthew Waters
fe1c7dfdc6 gmain: move source destroy write unlock slightly earlier
If a source is using g_source_set_callback_indirect(), then performing
GSource operations within GSourceCallbackFuncs::unref should not cause a
deadlock.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3725
2025-07-09 11:59:17 +10:00
Christoph Martin
032aea93d2 testprogramrunner: enable setting cwd
Add a mechanism to change the current working directory the program
under test is being run from.
2025-07-08 22:59:56 +02:00
Michael Catanzaro
25a176869d Merge branch 'gio-launch-quotes' into 'main'
gio-tool-launch: Fix mismatched curly quotes in translatable strings

See merge request GNOME/glib!4683
2025-07-08 08:05:40 -05:00
Philip Withnall
e6b4c28bba Merge branch 'string_expand_oflow' into 'main'
gstring: Improve g_string_expand/g_string_append_len_inline checks

See merge request GNOME/glib!4681
2025-07-08 13:01:05 +00:00
Tobias Stoeckmann
3752760c50 gstring: Improve g_string_append_len_inline checks
Use the same style for the G_LIKELY check here as in g_string_sized_new.
The check could overflow on 32 bit systems.

Also improve the memcpy/memmove check to use memcpy if val itself is
adjacent to end + len_unsigned, which means that no overlapping exists.
2025-07-08 14:30:38 +02:00
Tobias Stoeckmann
6aa97beda3 gstring: Fix g_string_sized_new segmentation fault
If glib is compiled with -Dglib_assert=false, i.e. no asserts
enabled, then g_string_sized_new(G_MAXSIZE) leads to a segmentation
fault due to an out of boundary write.

This happens because the overflow check was moved into
g_string_maybe_expand which is not called by g_string_sized_new.

By assuming that string->allocated_len is always larger than
string->len (and the code would be in huge trouble if that is not true),
the G_UNLIKELY check in g_string_maybe_expand can be rephrased to
avoid a potential G_MAXSIZE overflow.

This in turn leads to 150-200 bytes smaller compiled library
depending on gcc and clang versions, and one less check for the most
common code paths.

Reverts https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4655 and
reorders internal g_string_maybe_expand check to still fix
CVE-2025-6052.
2025-07-08 14:30:26 +02:00
Philip Withnall
8b05d8e95d gio-tool-launch: Fix mismatched curly quotes in translatable strings
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-07-08 11:11:40 +01:00
Philip Withnall
4d37bfb391 Merge branch 'backtrace' into 'main'
gbacktrace: Correctly wait for children on Unix

See merge request GNOME/glib!4680
2025-07-07 22:36:52 +00:00
Patrick Griffis
e419c1e10d inet-address: Ignore windows specific failure
In this case getaddrinfo on Windows succeeds at parsing something that fails on Linux.
2025-07-07 15:45:50 -05:00
Tobias Stoeckmann
d30bba26ea gbacktrace: Correctly wait for children on Unix
The WIF* macros are supposed to be used with the status, not the pid.

Also, only check the status if no error occurred, otherwise the value
might be uninitialized. If an unrecoverable error occurs, break the
loop (could happen if SIGCHLD is ignored).
2025-07-07 20:21:00 +02:00
Patrick Griffis
7e85ae9d5f ginetaddress: Scope ID parsing is not supported on win32
getaddrinfo doesn't parse it on Windows. This could be replaced by more manual parsing in the future.
2025-07-07 11:24:11 -05:00
Philip Withnall
d0f31c23d5 Merge branch 'fix_file_enumerator' into 'main'
gio: call g_file_enumerator_close in dispose instead of finalize

Closes #3713

See merge request GNOME/glib!4672
2025-07-07 12:35:50 +00:00
Marco Trevisan
dee8b23aeb Merge branch '3721-display-name-leak2' into 'main'
glocalfile: Fix another leak in g_local_file_set_display_name()

Closes #3721

See merge request GNOME/glib!4678
2025-07-07 14:29:07 +02:00
fbrouille
02597ca9d2 gio: call g_file_enumerator_close in dispose
`g_file_enumerator_finalize` should not call `g_file_enumerator_close`
because object parts (i.e. subclass variable and/or resources) might
already be freed, causing memory safety issues.
A better place to call `g_file_enumerator_close` is
`g_file_enumerator_dispose` because it is safe to access the object
memory here.

Fixes #3713

Signed-off-by: fbrouille <150549-fbrouille@users.noreply.gitlab.gnome.org>
2025-07-07 13:01:49 +01:00
Philip Withnall
acfe9d043f glocalfile: Fix another leak in g_local_file_set_display_name()
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3721
2025-07-07 12:58:59 +01:00
Marco Trevisan
29b47390c5 Merge branch 'mcatanzaro/#3721' into 'main'
Fix GFile leak in g_local_file_set_display_name()

Closes #3721

See merge request GNOME/glib!4677
2025-07-07 03:40:47 +02:00
Michael Catanzaro
0d845f3816 Fix GFile leak in g_local_file_set_display_name()
Fixes #3721
2025-07-06 17:34:48 -05:00
Patrick Griffis
b40194865a Unify address parsing for GInetAddress and GInetSocketAddress
This allows scope-ids to work for GInetAddress
2025-07-03 16:53:52 -05:00
Patrick Griffis
ed8bae5483 socket-testclient: Fix leaking debug strings 2025-07-03 16:11:29 -05:00
Patrick Griffis
bb8281fa72 socket-testclient: Include scope-id in debug output 2025-07-03 16:11:29 -05:00
Patrick Griffis
984d5cb199 socket-testclient: Support connecting to IPv6 addresses
Each enumerated address can be of a different family type, so you have to make a socket after you have that information.

As this is just a test client we make a new socket each time for simplicity.
2025-07-03 11:05:23 -05:00
Patrick Griffis
d03f495b31 gsocketaddress: Set scope-id and flowinfo of ginetaddress 2025-07-03 11:05:23 -05:00
Patrick Griffis
73d0627bda ginetaddress: Add scope-id and flowinfo properties
This will be used by GResolver as DNS responses include this
information along with the address.
2025-07-03 11:05:23 -05:00
Philip Withnall
804553b126 Merge branch 'mcatanzaro/#3716' into 'main'
gfileutils: fix computation of temporary file name

Closes #3716

See merge request GNOME/glib!4674
2025-07-01 17:11:44 +00:00
Michael Catanzaro
61e9632848 gfileutils: fix computation of temporary file name
We need to ensure that the value we use to index into the letters array
is always positive.

Fixes #3716
2025-07-01 11:00:44 -05:00
Philip Withnall
db3c92d3ab Merge branch 'genum-annotations' into 'main'
Add missing `(array zero-terminated=1)` annotations

See merge request GNOME/glib!4669
2025-06-25 13:06:22 +00:00
Jan-Willem Harmannij
5b5c3f43a5 Add missing (array zero-terminated=1) annotations
Array annotations were missing on:
- g_enum_complete_type_info
- g_flags_complete_type_info
- g_type_module_register_enum
- g_type_module_register_flags
2025-06-22 23:00:50 +02:00
Philip Withnall
cf776d1ac6 Merge branch 'gsettings_closure' into 'main'
Incorrect output parameter handling in closure helper of g_settings_bind_with_mapping_closures

See merge request GNOME/glib!4667
2025-06-19 12:32:26 +00:00