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

9513 Commits

Author SHA1 Message Date
t00mietum
8bd4d6c207 win32: Fix leak of the new name in file monitor renames
g_win32_fs_monitor_handle_event() converts the new name of a rename
to UTF-8 and passes it to g_file_monitor_source_handle_event(), which
takes it as const and copies what it keeps. Nothing freed it, so every
reported rename leaked the string.
2026-10-22 09:19:24 -07:00
Philip Withnall
03601a174c glocalfile: Move file system types to a const array
Rather than looking up the file system type with a 100-element `switch`
block, use `bsearch()`. At higher optimisation levels, modern GCC can
unwrap libc’s `bsearch()` and inline the comparison function, reducing
about 400 comparison/jump instructions to less than 30 implementing the
binary search.

See https://godbolt.org/z/cn88aado5

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-10-21 23:59:39 +01:00
Philip Withnall
b683d23e85 Merge branch 'gdesktopappinfo-fixes' into 'main'
Minor fixes to GDesktopAppInfo

See merge request GNOME/glib!5416
2026-10-21 18:44:43 +00:00
Ignacy Kuchciński
f310caad7a gdesktopappinfo: Handle minimal app infos when saving
Currently `g_desktop_app_info_ensure_saved()` assumes that if the object
does not have a filename, it was created with
`g_app_info_create_from_commandline()`, and therefore assumes
`info->exec`, `info->name` and `info->comment` are not NULL.

However, app info could have been also created with
`g_desktop_app_info_new_from_keyfile()`, which does not guarantee any of
those values. This results in failed assertions and broken resulting
filename, if these keys are not set in the key file.

The Name key is required by the Desktop Entry Specification, so make
`g_desktop_app_info_new_from_keyfile()` error out when the name is
missing, and check the remaining values in
`g_desktop_app_info_ensure_saved()`.
2026-10-21 14:43:08 +02:00
Benjamin Otte
e0fe82f583 socks5: Handle g_inet_address_new_from_string() returning NULL
This should only happen in rare corner cases, but it can happen.

Related: #4049
2026-10-21 13:33:13 +02:00
Benjamin Otte
5965f5562d socks4: Handle g_inet_address_new_from_string() returning NULL
Related: #4049
2026-10-21 13:33:13 +02:00
Eugenio Depalo
7f104fcf95 gactiongroup: Annotate nullable query outputs
g_action_group_query_action() sets parameter_type to NULL for actions
without a parameter, state_type and state to NULL for stateless
actions, and state_hint to NULL when there is no hint. The matching
g_action_group_get_action_*() getters already mark these results as
nullable.
2026-10-20 17:18:40 +02:00
Eugenio Depalo
8c0a7279ba gfileenumerator: Annotate nullable iteration outputs
A successful g_file_enumerator_iterate() call returns NULL outputs at
exhaustion. Optional output locations and borrowed result lifetimes
remain unchanged.
2026-10-16 21:25:25 +02:00
Ignacy Kuchciński
692e2f56f5 gdesktopappinfo: Remove unused error code path
Currently `g_desktop_app_info_set_as_default_for_type()` and
`g_desktop_app_info_set_as_last_used_for_type()` check if application's
ID is NULL, and error out accordingly.

This is because back when this mechanism was introduced in
229234111c,
app infos created with `g_desktop_app_info_new_from_filename()` would not
have application's ID set. However, since
c0af442909
and then
f065497acf
the application's ID is expected not to be empty. Moreover,
`g_desktop_app_info_ensure_saved()` guarantees it's set if it returns
true, so the error can never be returned.

Drop the unused check and error in those cases.
2026-10-15 21:37:34 +02:00
otaxhu
6ac3f4cf3b win32: require Windows 10+ and deprecate UWP-only apps 2026-10-14 15:31:31 -04:00
John Cardullo
cd999447a0 tests: Add unit tests for g_app_info_launch_uris_async() via spawn path
Verify that g_app_info_launch_uris_async() succeeds, propagates errors,
and handles cancellation properly for spawned applications.
2026-10-13 12:32:08 -07:00
John Cardullo
7071e19ca3 gdesktopappinfo: Add g_desktop_app_info_launch_uris_with_spawn_async()
- Factor the core spawning logic into an internal helper.
- Add g_desktop_app_info_launch_uris_with_spawn_async() and _finish()
  to handle their own GTask lifecycle, cancellation, and D-Bus flushing.
- Retain g_desktop_app_info_launch_uris_with_spawn() as a synchronous wrapper
  for existing sync callers.
- Update launch_uris_bus_get_cb() to delegate to the async variant instead of
  calling the synchronous spawn function.
2026-10-13 12:32:08 -07:00
John Cardullo
f6fc9d478f gdesktopappinfo: Move session bus flush into g_desktop_app_info_launch_uris_with_spawn()
Instead of calling g_dbus_connection_flush() in callers such as
g_desktop_app_info_launch_uris_internal() and
g_desktop_app_info_launch_action(), move the flush into
g_desktop_app_info_launch_uris_with_spawn().

This makes g_desktop_app_info_launch_uris_with_spawn() self-contained
in flushing the startup notification D-Bus messages it emits.

The flush was originally added in commit d6954c78 specifically to ensure
that fire-and-forget D-Bus signals emitted for startup notification
(notify_desktop_launch()) were not dropped if the session bus connection
was unreffed immediately afterwards.

Because notify_desktop_launch() is only called in the spawn path, the
other callers do not emit startup notification signals. The D-Bus
activation paths (g_desktop_app_info_launch_uris_with_dbus() and
g_desktop_app_info_launch_action()) use method calls whose lifecycle is
managed by GTask (which holds a reference to the connection until
complete), so they do not require an explicit flush.
2026-10-13 12:32:08 -07:00
Philip Withnall
a4c0fcdf32 gfdonotificationbackend: Fix leak of a GVariant
`g_variant_builder_end()` returns a new floating reference. We don’t
want to pass a floating reference into the `before_emit()` and
`after_emit()` vfuncs, in case they sink it, so let’s sink it first and
then unref later to avoid the leak.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: #4072
2026-10-13 14:44:53 +01:00
Philip Withnall
90d5c34f6e Merge branch 'messages-not-leak' into 'main'
gmessages: Fix an unused variable warning

See merge request GNOME/glib!5399
2026-10-12 09:25:54 +00:00
Philip Withnall
168e378526 gtask: Mark trace variables as potentially unused
If GLib is compiled without sysprof support, these will be unused.

See https://gitlab.gnome.org/pwithnall/glib/-/jobs/7171057

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-10-10 22:40:33 +01:00
Sam Sheridan
3daf62b374 gfile: Copy in bounded chunks with copy_file_range()
copy_file_range_with_progress() asked for the whole remaining length in
each copy_file_range() call, and only reported progress and checked the
cancellable between calls. Linux returns after at most 2GB, but FreeBSD
copies the full length in one call when the source and destination are
on different file systems. A large copy there reported no progress until
it had finished, and cancelling it took effect only once the whole file
had been copied.

Copy at most 8MiB per call. That gives about one progress update a
second on a slow USB stick; on fast storage the extra system calls are
negligible.

Closes #4069
2026-10-09 12:59:54 +01:00
Philip Withnall
8a41efe9c0 Merge branch 'fdo-notifications-activation-token' into 'main'
gfdonotificationbackend: Activate window with the activation-token

See merge request GNOME/glib!5384
2026-10-09 10:39:58 +00:00
SnoutFirst
5ca673db81 gio: Add G_MOUNT_MOUNT_READ_ONLY flag
Add a new flag to GMountMountFlags that allows callers to request
a read-only mount. This is needed by file managers (e.g. Thunar)
to allow users to mount removable drives as read-only.

The flag is passed through the GVolumeIface::mount_fn vfunc and
can be handled by volume monitor implementations (e.g. gvfs
udisks2) to pass the appropriate options to the underlying
mount mechanism.

Also add a --read-only / -r option to the gio mount CLI tool.
2026-10-06 21:14:14 +00:00
Philip Withnall
42a01cbb97 Merge branch 'gdesktopappinfo-disable-setuid-persistence' into 'main'
gdesktopappinfo: Disable persistence when running setuid

Closes #4003

See merge request GNOME/glib!5330
2026-10-06 20:46:29 +00:00
Philip Withnall
094f8ed5f8 Merge branch 'wip/3v1n0/ci-sanitizer-tests' into 'main'
CI: Add address (asan) and thread sanitizer (tsan) jobs

Closes #3356

See merge request GNOME/glib!4062
2026-10-06 15:14:53 +00:00
Alessandro Astone
382ac14a81 gfdonotificationbackend: Activate window with the activation-token
Handles the org.freedesktop.Notifications.ActivationToken signal.
2026-10-06 14:58:23 +02:00
Philip Withnall
d60cd821b7 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 12:35:19 +01:00
Benjamin Otte
7bc0696d48 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-09-24 13:08:52 +00:00
Benjamin Otte
2b6997df6b 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-09-24 13:08:52 +00:00
Benjamin Otte
026c263a53 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-09-24 13:08:52 +00:00
Benjamin Otte
82378dc348 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-09-24 13:08:52 +00:00
Benjamin Otte
3f0ec7af7c 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-09-24 13:08:52 +00:00
Benjamin Otte
5e55178fec 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-09-24 13:08:52 +00:00
Philip Withnall
4335e15da8 gfileenumerator: Reformat docs to fully use gi-docgen and match style guide
https://developer.gnome.org/documentation/guidelines/devel-docs.html#writing-api-references

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3250
2026-09-22 18:38:48 +01:00
Philip Withnall
5a124d1e66 Merge branch '4060-standard-name' into 'main'
glocalfile: Request standard::name when enumerating files

Closes #4060

See merge request GNOME/glib!5372
2026-09-22 16:45:48 +00:00
Philip Withnall
f8ff3d0261 Merge branch 'fix-gcharsetconverter-invalid-iconv' into 'main'
gcharsetconverter: Avoid closing invalid iconv descriptors

See merge request GNOME/glib!5370
2026-09-22 15:20:36 +00:00
Philip Withnall
0761f49fa1 gfileenumerator: Document STANDARD_NAME requirement for iterate()
It requires a `standard::name` to be available in order to be able to
iterate.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-09-22 15:02:11 +01:00
Philip Withnall
6f6b740f87 gio-tool-list: Request standard::name when enumerating files
As required by the docs for `g_file_enumerate_children()`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-09-22 12:05:43 +01:00
Philip Withnall
45d79ce5a9 glocalfile: Request standard::name when enumerating files
As required by the docs for `g_file_enumerate_children()`.

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

Fixes: #4060
2026-09-22 12:04:04 +01:00
Petr Sumbera
2537c015ce gcharsetconverter: Avoid closing invalid iconv descriptors
g_iconv_open() returns (GIConv) -1 on failure, but finalization
treated that sentinel as a valid descriptor. This can crash native iconv
implementations which do not tolerate it, including Solaris.

Preserve NULL as the not-initialized state, skip both invalid descriptor
values during finalization, and add coverage for unsupported charsets and
initialization which fails before opening a converter.
2026-09-22 09:24:01 +00:00
Kashyap Ekbote
3457cf6642 inotify: don't remove shared kernel watch while still in use
inotify watches are keyed by inode, so watching a directory (or file)
through two different paths that resolve to the same inode - e.g. a real
path and a symlink alias - returns the same watch descriptor (wd). The
backend already tracks this by keeping a GList of watched dirs/files per
wd.

However, when a monitor was cancelled, _ip_stop_watching() (and likewise
ip_watched_file_stop()) called _ik_ignore() -> inotify_rm_watch() as soon
as that particular path had no subscribers, without checking whether any
other path still shared the same wd. This tore down the single kernel
watch out from under the still-active monitors on the other path: they
kept reporting g_file_monitor_is_cancelled() == FALSE but silently
stopped receiving events.

Only remove the kernel watch once no other watched directory/file still
references the wd, by removing our own entry from the wd hash first and
issuing _ik_ignore() only when the list has become empty.

Add a regression test covering cancellation of a directory monitor
established through a symlink alias.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/4055
2026-09-20 10:02:36 +05:30
Philip Withnall
4699315caa Merge branch 'RHEL-215289' into 'main'
gresource: Avoid underflow

See merge request GNOME/glib!5363
2026-09-15 14:49:00 +00:00
Matthias Clasen
33bf3be6e6 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-09-14 10:34:53 -04:00
Benjamin Otte
643a45fa1b 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-09-10 18:24:17 +02:00
Philip Withnall
7b23d217fe goutputstream: Fix an unused-variable warning with G_DISABLE_ASSERT
`op` is only used in an assert.

Fixes the `G_DISABLE_ASSERT` CI job:
https://gitlab.gnome.org/GNOME/glib/-/jobs/6975634.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-09-08 23:17:22 +01:00
Hyunsik Parker
9242f5788c gio: Keep GDBusActionGroup headers compatible with C99
Closes: #4040
2026-09-08 21:49:18 +00:00
Marco Trevisan (Treviño)
f8cd442d73 build: Mark all the failing and flacky tests with thread sanitizer
Sadly many tests don't pass with thread sanitizer, but better to
mark them as such to try to fix them in the future

See also: https://gitlab.gnome.org/GNOME/glib/-/issues/1672
2026-08-30 00:34:48 +02:00
Marco Trevisan (Treviño)
7af6d13034 gio/tests/gdbus-tool: Ignore leaks due to PyGObject 2026-08-30 00:34:48 +02:00
Marco Trevisan (Treviño)
7282c2a8c6 build: Preload sanitizer libraries before than any other library
In some test cases (but not only) GLib needs to preload libraries when
launching executables, however this doesn't work well with ASAN because
libasan needs to be the first library to be loaded in such case.

We've been ignoring the error so far, using verify_asan_link_order=false
ASAN option, but this is not the correct way because it implies that
we don't check any pre-loaded library, as we instead should.

So in the platforms we know, get the proper sanitizer libraries paths
and pre-load them when required.

We don't do it for installed tests since the full paths may change in
the target system, so ignoring the error is safer.

This meson code has been used for various years now in fprintd project
to run tests in CI in both fedora and debian-based systems with no
issues, so I consider it reliable.

In case no preload variables are found the default ignore mode is used
2026-08-30 00:34:48 +02:00
Marco Trevisan (Treviño)
7296505ddb build/tests: Automatically set ASAN_OPTIONS if preloading is required
If preloading a library is required asan doesn't work properly because
it requires to be the first loaded library to test everything, however
the behavior can be worked around using an ASAN_OPTIONS variable, so do
this to prevent the tests to fail completely

But instead of having to do it at test level, manage this at wider scope
2026-08-30 00:24:57 +02:00
Marco Trevisan (Treviño)
e9473f27da build: Define the preload variable name and separator globally
We may need this in multiple tests, so let's share the value
2026-08-30 00:24:57 +02:00
Marco Trevisan (Treviño)
9f61953056 glib, gio: Apply the same rules to both gcc and clang when appropriate 2026-08-30 00:24:45 +02:00
Samy
18ba843141 gdesktopappinfo: Disable persistence when running setuid
The directories used for desktop application persistence are derived from
the user environment. In a setuid process, an unprivileged user can redirect
those writes through an intermediate symlink.

GIO is not designed for privileged use, so fail closed before resolving or
creating any user application or MIME configuration directory.

Closes #4003

Signed-off-by: Samy <samy@ap4.sh>
2026-08-28 22:02:24 +02:00
Philip Withnall
2f13f6af0d Merge branch 'main' into 'main'
fix: handle long filenames in trash by truncating from front

See merge request GNOME/glib!5311
2026-08-26 09:06:01 +00:00