Commit Graph

32174 Commits

Author SHA1 Message Date
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
Mark Nauwelaerts
bd20507909 gsettings: adjust closure helpers in g_settings_bind_with_mapping_closures
... to handle an output value parametere
2025-06-18 19:52:59 +02:00
Mark Nauwelaerts
9ee245b78e tests: gsettings: extend g_settings_bind_with_mapping_closures test
... so as to fail with current implementation
2025-06-17 18:18:40 +02:00
Philip Withnall
dc6f9447cd Merge branch 'g_match_info_fetch_pos_desc' into 'main'
docs: clarifying return values from g_match_info_fetch_pos

Closes #2848

See merge request GNOME/glib!4664
2025-06-17 13:07:04 +00:00
Mark Lautman
bd36359ed8 docs: clarifying return values from g_match_info_fetch_pos
Details the returned function value, start_pos, and end_pos for various scenarios of capture parenthesis and GMatchInfo.

Closes #2848
2025-06-17 13:07:04 +00:00
Philip Withnall
f0f1c64c5b Merge branch 'fix-do-not-queue-docs' into 'main'
gio: enums: Fix GBusNameOwnerFlags's annotation

See merge request GNOME/glib!4665
2025-06-17 10:39:46 +00:00
Maximiliano Sandoval
d02f59a54b gio: enums: Fix GBusNameOwnerFlags's annotation
g-ir-scanner won't pick Since or Deprecated annotations if they are
inlined, they need a dedicated documentation block for this to work. The
since annotation is used, e.g. in gtk-rs, to not expose enum flags if
not compiled declaring we have a new enough glib version.
2025-06-16 17:57:53 +02:00
Philip Withnall
c1e8174992 2.85.1
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.85.1
2025-06-13 12:28:00 +01:00
Philip Withnall
e897df0e45 Merge branch 'gio-unix-docs-fix' into 'main'
docs: Stop hiding the Unix-like APIs which are in Gio-2.0.gir

See merge request GNOME/glib!4657
2025-06-13 11:03:37 +00:00
Philip Withnall
96aa5f1b1f Merge branch 'check-recursive-trashing' into 'main'
glocalfile: Verify deleting from trash beforehand

Closes #1665

See merge request GNOME/glib!4653
2025-06-12 16:01:15 +00:00
Philip Withnall
0bd51d8f8b Merge branch 'meson-use-localedir-opt' into 'main'
meson: Use the appropriate localedir option

See merge request GNOME/glib!4661
2025-06-12 12:20:03 +00:00