31301 Commits

Author SHA1 Message Date
Marco Trevisan (Treviño)
695cdcdba4 glib/tests/gvariant: Not try to memcpy NULL data
It's undefined behavior
2025-02-11 17:46:07 +01:00
Marco Trevisan (Treviño)
c0f8f24969 gvariant-core: Add pre-condition on variant store data being non-null
We define the data not-nullable in docs, but we didn't check this
prerequisite programmatically
2025-02-11 17:46:07 +01:00
Marco Trevisan (Treviño)
01b195e0c6 gvariant: Do not byteswap empty GVariant values
If a value has no size, we'd end up to use g_variant_store() with a NULL
value, and this is not allowed by the API, leading to errors:

stderr:
 ../glib/gvariant-core.c:1429:9: runtime error: null pointer passed as argument
    1, which is declared to never be null
    #0 0x7f9c139ce559 in g_variant_store ../glib/gvariant-core.c:732
    #1 0x7f9c13c60b01 in g_variant_byteswap ../glib/gvariant.c:6211
    #2 0x564ae412e9b9 in test_byteswap ../glib/tests/gvariant.c:2321
    #3 0x564ae412e9b9 in test_byteswaps ../glib/tests/gvariant.c:2374
    #4 0x7f9c13bc1000 in test_case_run ../glib/gtestutils.c:3115
    #5 0x7f9c13bc1000 in g_test_run_suite_internal ../glib/gtestutils.c:3210
    #6 0x7f9c13bc0d7b in g_test_run_suite_internal ../glib/gtestutils.c:3229
    #7 0x7f9c13bc0d7b in g_test_run_suite_internal ../glib/gtestutils.c:3229
    #8 0x7f9c13bc2019 in g_test_run_suite ../glib/gtestutils.c:3310
    #9 0x7f9c13bc216f in g_test_run ../glib/gtestutils.c:2379
    #10 0x564ae410f326 in main ../glib/tests/gvariant.c:6045
2025-02-11 17:46:07 +01:00
Marco Trevisan (Treviño)
d1b4f169a8 gbytes: Return early if a NULL or 0-sized GBytes is created
In case data is NULL we ended up to call memcpy with NULL parameter
which is undefined behavior (see the trace below).

So instead of having multiple null checks to do just the same, simplify
the NULL or 0-sized cases.

../glib/gbytes.c:140:7: runtime error: null pointer passed as argument 2,
  which is declared to never be null
    #0 0x7f56ea7c667e in g_bytes_new ../glib/gbytes.c:140
    #1 0x5557c3659f06 in test_null ../glib/tests/bytes.c:453
    #2 0x7f56ea9c0f70 in test_case_run ../glib/gtestutils.c:3115
    #3 0x7f56ea9c0f70 in g_test_run_suite_internal ../glib/gtestutils.c:3210
    #4 0x7f56ea9c0ceb in g_test_run_suite_internal ../glib/gtestutils.c:3229
    #5 0x7f56ea9c1f89 in g_test_run_suite ../glib/gtestutils.c:3310
    #6 0x7f56ea9c20df in g_test_run ../glib/gtestutils.c:2379
    #7 0x5557c36599d2 in main ../glib/tests/bytes.c:536
2025-02-11 17:46:07 +01:00
Marco Trevisan (Treviño)
7ae8b1d132 gio/tests/gdbus-export: Ensure we call all the callbacks on return
Ensure we don't do an user-after-free access, as reported by ASAN:

  ==3704==ERROR: AddressSanitizer: stack-use-after-return on address
   0x70a58f8631c0 at pc 0x000000405144 bp 0x7fffff62c7a0 sp 0x7fffff62c798
   READ of size 4 at 0x70a58f8631c0 thread T0
    #0 0x405143 in on_object_unregistered ../../GNOME/glib/gio/tests/gdbus-export.c:597
    #1 0x70a592e858d8 in call_destroy_notify_data_in_idle ../../GNOME/glib/gio/gdbusconnection.c:244
    #2 0x70a5940016a4 in g_idle_dispatch ../../GNOME/glib/glib/gmain.c:6221
    #3 0x70a59401095b in g_main_dispatch ../../GNOME/glib/glib/gmain.c:3348
    #4 0x70a59401095b in g_main_context_dispatch_unlocked ../../GNOME/glib/glib/gmain.c:4197
    #5 0x70a59401ba17 in g_main_context_iterate_unlocked ../../GNOME/glib/glib/gmain.c:4262
    #6 0x70a59401cc73 in g_main_context_iteration ../../GNOME/glib/glib/gmain.c:4327
    #7 0x405658 in test_threaded_unregistration_iteration ../../GNOME/glib/gio/tests/gdbus-export.c:1878
    #8 0x405658 in test_threaded_unregistration ../../GNOME/glib/gio/tests/gdbus-export.c:1952
    #9 0x70a5940dfb04 in test_case_run ../../GNOME/glib/glib/gtestutils.c:2988
    #10 0x70a5940dfb04 in g_test_run_suite_internal ../../GNOME/glib/glib/gtestutils.c:3090
    #11 0x70a5940df893 in g_test_run_suite_internal ../../GNOME/glib/glib/gtestutils.c:3109
    #12 0x70a5940df893 in g_test_run_suite_internal ../../GNOME/glib/glib/gtestutils.c:3109
    #13 0x70a5940e0bc9 in g_test_run_suite ../../GNOME/glib/glib/gtestutils.c:3189
    #14 0x70a5940e0d1f in g_test_run ../../GNOME/glib/glib/gtestutils.c:2275
    #15 0x40eb72 in session_bus_run ../../GNOME/glib/gio/tests/gdbus-sessionbus.c:69
    #16 0x403a2c in main ../../GNOME/glib/gio/tests/gdbus-export.c:1990
    #17 0x70a591d9f149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 0d710e9d9dc10c500b8119c85da75004183618e2)
    #18 0x70a591d9f20a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 0d710e9d9dc10c500b8119c85da75004183618e2)
    #19 0x403b44 in _start (/tmp/_build/gio/tests/gdbus-export+0x403b44) (BuildId: f6312e919c3d94e4c49270b0dfc5c870e1ba550b)

Address 0x70a58f8631c0 is located in stack of thread T0 at offset 192 in frame
    #0 0x40525f in test_threaded_unregistration ../../GNOME/glib/gio/tests/gdbus-export.c:1936

  This frame has 7 object(s):
    [32, 40) 'local_error' (line 1835)
    [64, 72) 'unregister_thread' (line 1836)
    [96, 104) 'value' (line 1838)
    [128, 136) 'value_str' (line 1839)
    [160, 168) 'call_result' (line 1840)
    [192, 204) 'object_registration_data' (line 1834) <== Memory access at offset 192 is inside this variable
    [224, 240) 'data' (line 1833)
2025-02-11 17:29:35 +01:00
Marco Trevisan (Treviño)
be01334bc6 gio/tests/gdbus-connection: Fix typo 2025-02-11 17:29:35 +01:00
Marco Trevisan (Treviño)
1a72a697ad glib/glib-private: Mark the dynamic LSAN checks as unlikely
It's not normal to run programs with leak sanitizer enabled, so let's
mark those checks as such, in case the compiler can optimize them
2025-02-11 17:29:35 +01:00
Marco Trevisan (Treviño)
0bb6841568 gcharset: Mark cached data as known leak
The charset data is never freed but it's something stored per thread
so we can safely ignore the leak
2025-02-11 17:29:35 +01:00
Marco Trevisan (Treviño)
a04163d8ac gthread: Mark data allocated with g_private_set_alloc0 as leaking
This is what we already ignored with valgrind and it's something that
we should always ignore since it's leaked by design.

So do explicitly mark it as such.
2025-02-11 17:29:35 +01:00
Marco Trevisan (Treviño)
c91dc83fb0 girepository/parser: Clarify ownership of nodetype nodes
We may had free'd a list of items without freeing the items in there.
So now, properly steal the data instead and free everything.
2025-02-11 17:29:35 +01:00
Marco Trevisan (Treviño)
aaf93f9851 girepository/compiler: Cleanup the parser error on failure 2025-02-11 15:19:53 +01:00
Marco Trevisan (Treviño)
9b7ac7e225 girepository/compiler: Cleanup the parser on write failures 2025-02-11 15:19:53 +01:00
Marco Trevisan
589c8295ea Merge branch 'callable-info-test-leak' into 'main'
tests: Fix a memory leak if a callable-info test is skipped

See merge request GNOME/glib!4483
2025-02-11 13:57:20 +00:00
Philip Withnall
ca760eeeac Merge branch 'windows-fix-shebang' into 'main'
Windows: fix Python path can contain spaces

Closes #3331

See merge request GNOME/glib!4391
2025-02-11 13:42:32 +00:00
Dan Yeaw
160e55575e Windows: fix Python path cannot contain spaces
Move the shebang line from the full Python path of the build
machine to the first Python on the path during runtime. Set
the shebang in the main meson.build file so that it can be
overridden in one place if needed.

Fixes: #3331
2025-02-11 11:57:30 +00:00
Philip Withnall
a127f9b7d2
tests: Fix a memory leak if a callable-info test is skipped
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-11 11:40:29 +00:00
Philip Withnall
8d51095602 Merge branch 'gkeyfile-fix-c-locale-handling' into 'main'
gkeyfile: Fix C locale handling

Closes #3578

See merge request GNOME/glib!4480
2025-02-11 09:31:33 +00:00
Gaël Bonithon
5cc6af2237 gkeyfile: Fix C locale handling
As gettext does:
* if C locale is used to set a value, set the untranslated value, i.e.
  key=value and not key[C]=value;
* if C locale is used to get a value, return the untranslated value,
  i.e. not the value from key[C]=value, if it ever exists, and do not
  consider C as an undefined locale otherwise.

Fixes: #3578
2025-02-11 09:31:33 +00:00
Philip Withnall
ba60ea7aa0 Merge branch 'amolenaar/docs-fixes' into 'main'
docs: Make docs more markdown-ish

See merge request GNOME/glib!4479
2025-02-10 14:40:55 +00:00
Arjan Molenaar
04acc1741b
docs: Make docs more markdown-ish
Fixed some issues that came to light while compiling documentation
for the python bindings.
2025-02-10 10:26:42 +01:00
Philip Withnall
0234f8e1b1 Merge branch 'ppd-api-rename' into 'main'
gio/powerprofilemonitordbus: Use newer D-Bus API

See merge request GNOME/glib!4478
2025-02-07 08:34:19 +00:00
Marco Trevisan (Treviño)
dba2d618d5 gio/tests/power-profile-monitor*.py: Use upower ppd daemon APIs 2025-02-07 00:55:35 +01:00
Marco Trevisan (Treviño)
71d08b707a gio/tests/power-profile-monitor-*.py: Fix style using black 2025-02-07 00:55:35 +01:00
Marco Trevisan (Treviño)
236abac6fb gio/powerprofilemonitordbus: Use newer DBus API
Since some time the power-profiles-daemon project has been moved under
the upower umbrella and renamed its API to follow that.

While the legacy name is still supported, there are plans to not support
it anymore in future [2]. So let's update GLib code to use the
current main name instead.

[1] https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/merge_requests/148
[2] https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/merge_requests/166
2025-02-07 00:55:32 +01:00
Philip Withnall
00f54b1bcc Merge branch 'fix-docs-links' into 'main'
docs: Fix invalid references and broken links

See merge request GNOME/glib!4475
2025-02-06 12:38:51 +00:00
Mavroudis Chatzilazaridis
cb1502ed66 docs: Fix invalid references and broken links
This commit fixes quite a few broken links and references, minor typos,
and improves wording in some sections.
2025-02-05 22:28:26 +02:00
Michael Catanzaro
f5eb3fd716 Merge branch 'sysprof-leak' into 'main'
glib.supp: Ignore once-per-thread leak from SysprofCollector

See merge request GNOME/glib!4471
2025-02-05 17:33:40 +00:00
Philip Withnall
7fffe59037 Merge branch 'wip/pwithnall/soft-c11-dependency' into 'main'
build: Add a soft dependency on C11

See merge request GNOME/glib!4473
2025-02-04 16:35:33 +00:00
Philip Withnall
0445d555e0
docs: Stop mentioning outdated C versions in various docs
Link to the toolchain requirements, which are kept up to date, rather
than duplicating them across multiple documents.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 16:01:44 +00:00
Philip Withnall
445eea668a
build: Add a soft dependency on C11
This will warn if GLib is configured with a toolchain which doesn’t
support C11. We currently require C99. If nobody complains (as directed
by this warning) we will start to require C11 in the next unstable
release series (2.85).

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3574#note_1859924

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 15:59:51 +00:00
Philip Withnall
97fdba0d2f Merge branch 'cancellable-source-dispose-races' into 'main'
gcancellable: Ignore cancelled callback on disposed source

Closes #3448

See merge request GNOME/glib!4206
2025-02-04 14:40:56 +00:00
Philip Withnall
ff2c5c3e74
tests: Fix non-atomic accesses to atomic variables in cancellable test
As suggested by Marco Trevisan in !4206.

This might eliminate some spurious failures of the test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 14:06:15 +00:00
Marco Trevisan (Treviño)
d7c8bb0726 gcancellable: Ignore cancelled callback on disposed source
Prevent to access to a disposed gsource in the GCancellable cancelled
signal callback.

Due to the fact that the signal is called in the same thread in which
the cancellable get cancelled, we may receive the callback just after
the GSource has been disposed or during its disposal.

To prevent this, let's pass to the signal a pointer to the source itself
and nullify atomically the first time we're calling a callback or
disposing it.

In case the dispose function wins the race, then the callback will just
do nothing, while the disposal will continue as expected.

In case the callback wins the race, during the concurrent disposal we'll
just wait for the callback to be completed, before returning the disposal
itself that will likely lead to freeing the GSource.

Closes: #3448
2025-02-04 13:01:03 +00:00
Philip Withnall
eec7ba6ef3 Merge branch '3592-dbus-serial-overflow' into 'main'
gdbusconnection: Prevent sending a serial of zero on overflow

Closes #3592

See merge request GNOME/glib!4470
2025-02-04 11:09:45 +00:00
Philip Withnall
62c1ae7161
glib.supp: Ignore once-per-thread leak from SysprofCollector
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 10:47:43 +00:00
Philip Withnall
f7a0e5f13f Merge branch 'wip/nacho/gregistry' into 'main'
Registry backend fixes

See merge request GNOME/glib!4468
2025-02-04 10:40:03 +00:00
Philip Withnall
8297bbc00c
gdbusmessage: Check that message serial is not set to zero
It’s disallowed by the D-Bus specification.

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

Helps: #3592
2025-02-04 10:32:44 +00:00
Philip Withnall
b94b44407a
gdbusconnection: Prevent sending a serial of zero on overflow
It finally happened: someone managed to keep a process alive long
enough, and using a single `GDBusConnection`, to overflow the
`last_serial` counter in the connection and send an invalid message with
serial of zero (which is disallowed by the D-Bus specification).

Avoid that happening in future by skipping serials of zero on overflow,
and wrapping straight back around to 1.

This looks a little more confusing than it is, because `last_serial` is
pre-incremented on use, so to skip zero, we explicitly set it to zero.
This is exactly what happens when the `GDBusConnection` is initialised
anyway.

I can’t think of a way to add a unit test for this — there is no way to
affect the value of `last_serial` except by sending messages (each one
increments it), and in order to get it to overflow by sending messages
at 1kHz, the test would have to run for 49 days.

Instead, I tested this manually by temporarily modifying
`GDBusConnection` to initialise `last_serial` to `G_MAXUINT32 - 3`, then
checked that the unit tests all still passed, and that the overflow code
was being executed.

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

Fixes: #3592
2025-02-04 10:32:37 +00:00
Silvio Lazzeretti
23ad130b15 registrybackend: fix some memory leaks 2025-02-04 08:38:48 +01:00
Silvio Lazzeretti
f45b5ea776 registrybackend: make subscribe and unsubscribe thread-safe
The registry backend uses a thread to monitor
registry changes and send notifications.
The state of this thread and structures used
for communicating with it are kept in the watch
variable.
The subscribe and unsubscribe functions might be
concurrently called from multiple threads and
need to communicate with the monitoring thread.
For this reason we need to synchronize the access
to the watch variable.
2025-02-04 08:38:45 +01:00
Philip Withnall
e96bc30c16 Merge branch 'ebassi/goption-flag-deprecated' into 'main'
Add G_OPTION_FLAG_DEPRECATED

See merge request GNOME/glib!4046
2025-02-03 15:37:23 +00:00
Emmanuele Bassi
b145330b75 Add G_OPTION_FLAG_DEPRECATED
Generate a deprecation notice in the `--help` output for deprecated
options. This helps with the documentation of command line utilities.

Put the deprecation notice near the argument, to allow application
developers to add a notice on the deprecation on their own, and
explain what to use instead.
2025-02-03 15:37:23 +00:00
Philip Withnall
b9a4039271 Merge branch 'main' into 'main'
Add support for QNX8.0

See merge request GNOME/glib!4466
2025-02-03 15:10:06 +00:00
Philip Withnall
cac9100960 Merge branch 'ebassi/gtype-refcount' into 'main'
Drop TypeNode reference counting

See merge request GNOME/glib!3255
2025-02-03 14:38:24 +00:00
Emmanuele Bassi
dc86ad1925 Drop TypeNode reference counting
We don't allow unloading types, both static and dynamic, since 2013. The
code that deals with reference counting is mostly dead code, and makes
reasoning about the type system more complicated than necessary.

Since type classes and interfaces can only be instantiated, we introduce
explicit getter functions that create a GTypeClass or a GTypeInterface
vtable; the ref() and unref() API gets a "soft" deprecation (explicitly
not using `GOBJECT_DEPRECATED_IN_*` yet), to allow people to
progressively port their code.
2025-02-03 14:38:24 +00:00
Felix Xing
e99e27848e Add checking for <sys/ucred.h>
A new header check is added for non-standard <sys/ucred.h>. Some platforms, like Linux, might support <sys/param.h>, <sys/mount.h>, and <fstab.h> but not this. Which can cause compilation to fail for gio/gunixmounts.c
2025-02-03 09:19:17 -05:00
Philip Withnall
0621d0ddb8 Merge branch 'glib-function-pointer-requirements' into 'main'
Document function pointer cast requirements

Closes #3595

See merge request GNOME/glib!4469
2025-02-03 11:40:12 +00:00
Demi Obenour
9eb0828bd8 Document function pointer cast requirements
Helps: #3596
Fixes: #3595
2025-02-03 11:40:12 +00:00
Michael Catanzaro
9b1e0a583a Merge branch 'gi-static-vfuncs' into 'main'
Support static vfuncs in GIRepository

See merge request GNOME/glib!4457
2025-02-01 14:10:57 +00:00
Felix Xing
a177c46b19 Add support for QNX8.0
This request brings support to the latest version of QNX software. _g_get_unix_mount_points (void) for getfsent() system also works on QNX. To avoid duplicating codes, it will be reused.
2025-01-31 09:18:02 -05:00