Commit Graph

31520 Commits

Author SHA1 Message Date
Philip Withnall
7ea714e658 Merge branch 'wip/3v1n0/sanitizer-memory-fixes' into 'main'
Memory sanitizer fixes

See merge request GNOME/glib!4484
2025-04-03 13:04:05 +00:00
Marco Trevisan (Treviño)
03dcf4cdc3 glib/messages: Avoid warning on potentially uninitialized value
In function ‘memmem_with_end_pointer’,
    inlined from ‘domain_found’ at ../glib/gmessages.c:2695:16,
    inlined from ‘should_drop_message’ at ../glib/gmessages.c:2802:35:
../glib/gmessages.c:2674:19: warning: ‘log_domain_length’ may be used
    uninitialized [-Wmaybe-uninitialized]
 2674 | #define my_memmem memmem
      |                   ^
../glib/gmessages.c:2683:10: note: in expansion of macro ‘my_memmem’
 2683 |   return my_memmem (haystack, (const char *) haystack_end - (const char *) haystack, needle, needle_len);
      |          ^~~~~~~~~
../glib/gmessages.c: In function ‘should_drop_message’:
../glib/gmessages.c:2760:13: note: ‘log_domain_length’ was declared here
 2760 |       gsize log_domain_length;
      |             ^~~~~~~~~~~~~~~~~
2025-04-03 14:01:20 +02:00
Marco Trevisan (Treviño)
31c9dbbc73 glib/tests/gvariant: Not try to memcpy NULL data
It's undefined behavior
2025-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
39c05b1312 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-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
28037242d5 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-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
aee7b2b092 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-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
ea52feb658 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-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
6ed59a6f40 gio/tests/gdbus-connection: Fix typo 2025-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
efe215809b 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-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
b11c121747 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-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
0453908570 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-04-03 13:57:18 +02:00
Marco Trevisan (Treviño)
a3eccd6316 gthread: Clarify when g_private_set_alloc0() suppression happens with valgrind 2025-04-03 13:57:18 +02:00
Marco Trevisan (Treviño)
0a47b69b46 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-04-03 13:57:18 +02:00
Marco Trevisan (Treviño)
98de5367d3 girepository/compiler: Cleanup the parser error on failure 2025-04-03 13:57:18 +02:00
Marco Trevisan (Treviño)
cc070e1a7d girepository/compiler: Cleanup the parser on write failures 2025-04-03 13:57:18 +02:00
Philip Withnall
416bab52eb tests: Fix a memory leak if a callable-info test is skipped
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-03 13:57:18 +02:00
Michael Catanzaro
eedf75e810 Merge branch 'variant-type-docs' into 'main'
gvarianttype: Improve docs on type validation

See merge request GNOME/glib!4571
2025-04-02 16:04:25 +00:00
Emmanuele Bassi
93371e1f56 Merge branch 'dbus-name-owning-docs' into 'main'
gdbusnameowning: Convert docs to gi-docgen linking syntax

See merge request GNOME/glib!4562
2025-04-02 13:10:05 +00:00
Philip Withnall
4820b1bd79 Merge branch '3649-win32-wchar-crash' into 'main'
gwin32appinfo: Fix an incorrect size vs wide-length comparison

Closes #3649

See merge request GNOME/glib!4572
2025-04-02 11:35:12 +00:00
Philip Withnall
afb5ba1ea1 Merge branch 'doc-prgname' into 'main'
gutils: make documentation of g_set_prgname() clearer

See merge request GNOME/glib!4567
2025-04-02 10:48:53 +00:00
Integral
ead02072a4 gutils: make documentation of g_set_prgname() clearer 2025-04-02 18:33:38 +08:00
Philip Withnall
18eb38fa15 gvarianttype: Improve docs on type validation
Spotted by skrcprst.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-02 11:08:04 +01:00
Philip Withnall
f1a498e178 Merge branch 'protect-argv-string' into 'main'
gspawn-win32: Fix potential integer overflows in argv handling

See merge request GNOME/glib!4570
2025-04-01 16:14:35 +00:00
Philip Withnall
585ec33763 gwin32appinfo: Clarify some variable names
See the previous commit. Clarify these variable names so it’s more
obvious they contain a size in bytes rather than a length in wide-chars.

This introduces no functional changes.

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

Helps: #3649
2025-04-01 16:05:44 +01:00
Philip Withnall
6f9bb9b784 gwin32registrykey: Clarify that value sizes are in bytes
It can be confusing otherwise when getting string values: is the size in
bytes or wide-characters?

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

Helps: #3649
2025-04-01 16:04:01 +01:00
Philip Withnall
464dd6fb6b gwin32appinfo: Fix an incorrect size vs wide-length comparison
`value_size` is in bytes, whereas `ms_resource_prefix_len` is in wide
characters, so they cannot be compared directly. This meant that if
12 ≤ `value_size` < 24 then the call to `memcmp()` would read off the
end of `value`.

Fix it by using a wide-character and nul-aware comparison function and
operating only on wide-lengths. This is safe because
`g_win32_registry_key_get_value_w()` guarantees that string-typed return
values are nul-terminated.

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

Fixes: #3649
2025-04-01 15:50:00 +01:00
Philip Withnall
3d9cc10330 gspawn-win32: Fix potential integer overflows in argv handling
This can happen if a user passes a ludicrously long string to argv.

Spotted by chamalsl as #YWH-PGM9867-48.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-30 21:49:05 +01:00
Philip Withnall
7d74d4b5ab Merge branch 'compile-resources-docs' into 'main'
docs: Add some detail

See merge request GNOME/glib!4568
2025-03-30 20:36:22 +00:00
Philip Withnall
8eeb733a83 Merge branch 'romanian-updates' into 'main'
Update Romanian translation

See merge request GNOME/glib!4569
2025-03-30 20:34:41 +00:00
Antonio Marin
983619d7ed Update Romanian translation 2025-03-30 17:30:01 +00:00
Matthias Clasen
e8b9319a66 docs: Add some detail
Mention that glib-compile-resources accepts multiple --sourcedir
options.
2025-03-30 09:22:32 -04:00
Philip Withnall
913a1bfd85 Merge branch 'main' into 'main'
Fix LGPL in header

See merge request GNOME/glib!4565
2025-03-21 17:40:54 +00:00
Sebastian Wilhelmi
247e7b6995 Fix LGPL in header of gvarianttype-private.h 2025-03-21 17:40:53 +00:00
Philip Withnall
be031cf2a5 Merge branch 'test-path-fixes' into 'main'
tests: Various fixes to create temporary files in /tmp rather than the build directory

See merge request GNOME/glib!4561
2025-03-21 15:30:53 +00:00
Philip Withnall
ee4b93bff4 tests: Port spawn-test tests to use G_TEST_OPTION_ISOLATE_DIRS
This ensures they’re not writing files to the build directory, which
avoids race conditions when running multiple invocations of the tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:16 +00:00
Philip Withnall
e4fca24a06 tests: Add missing shell argument quoting in spawn-test
It’s not currently needed, because the filename being passed to the
subprocess is hard-coded and doesn’t contain anything which would need
escaping. But the following commit is going to change that (to avoid
filename collisions), so let’s fix the quoting first.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:11 +00:00
Philip Withnall
a795dede46 tests: Port mapping tests to use G_TEST_OPTION_ISOLATE_DIRS
This ensures they’re not writing files to the build directory, which
avoids race conditions when running multiple invocations of the tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:07 +00:00
Philip Withnall
484fb416c6 tests: Factor out hard-coded file names in mapping test
So the filename we delete at the end of the test is definitely the same
one we created at the start of the test.

This introduces no functional changes, but will make a refactor in the
following commit simpler.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:03 +00:00
Philip Withnall
9f75cdc2bc tests: Port keyfile tests to use G_TEST_OPTION_ISOLATE_DIRS
This ensures they’re not writing files to the build directory, which
avoids race conditions when running multiple invocations of the tests.

This is not entirely trivial, because the tests for
`g_key_file_load_from_data_dirs()` are affected by the overridden
`$XDG_DATA_HOME` directory. Mitigate that by copying the file they want
to that directory (and relying on `G_TEST_OPTION_ISOLATE_DIRS` to delete
it again afterwards).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:58 +00:00
Philip Withnall
87cc9f2b6d gkeyfile: Better document search algorithm for g_key_file_load_from_data_dirs()
Today I learned that it magically turns `-` into `/` to search
subdirectories for key files. Turns out that wasn’t documented at all.

i.e. it’ll search for `$datadir/some-key-file.ini` and, if that’s not
found, will then try `$datadir/some/key-file.ini` and then
`$datadir/some/key/file.ini`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:54 +00:00
Philip Withnall
e7b820d66c tests: Move various test paths to g_get_tmp_dir()
Rather than creating files in the current directory. This is a bit
neater, and avoids races between parallel invocations of the unit tests
if the file names aren’t guaranteed to be unique (e.g. by using
`g_mkstemp()`).

Add `G_TEST_OPTION_ISOLATE_DIRS` too, to make sure we use a unique
subdirectory of `g_get_tmp_dir()`. This means that paths like
`g_get_tmp_dir() / some-file` are guaranteed to be race-free even if the
filename is not unique, because the test tmp dir now is.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:49 +00:00
Philip Withnall
4d2b873211 tests: Use g_build_filename() rather than g_strdup_printf()
In the `g-file-info-filesystem-readonly` test.

This doesn’t introduce any functional changes, but makes the code a
little easier to read (because the parts of the path are now in
hierarchical order) and makes it a bit clearer that we’re building a
path rather than an arbitrary string.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:45 +00:00
Philip Withnall
447fa26205 gfileutils: Clarify that g_mkstemp() and friends act in the current directory
Otherwise it’s easy to assume that they create a file in the system
temporary directory, if they’re only called with a filename template
(without a path).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:41 +00:00
Philip Withnall
4345eb2756 tests: Only use g_mkstemp() in /tmp rather than current directory
It’s not entirely clear from the documentation, but `g_mkstemp()` (and
`g_mkdtemp()`) operate in the current directory, rather than the system
temporary directory.

This meant these tests were all writing files to the build directory.
This is messy, though thankfully not a correctness issue or a race
because `g_mkstemp()` guarantees to return a unique file for each
caller.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:36 +00:00
Philip Withnall
581a0b1285 gfile: Document that g_file_make_directory() returns G_IO_ERROR_EXISTS
if the directory already exists.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:32 +00:00
Philip Withnall
d77bff0bef tests: Use standard g_test_message() logging in fileutils tests
Rather than a custom combination of `g_test_verbose()` and
`g_printerr()`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:27 +00:00
Philip Withnall
918c4bd467 tests: Use g_assert_*() rather than g_assert() in fileutils tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:23 +00:00
Philip Withnall
aae1743284 tests: Test directories inside /tmp rather than arbitrary paths
This probably wasn’t causing any problems since it was a self-contained
read only access of a non-existent path. But it’s a bit tidier to
contain this all inside `/tmp`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:18 +00:00
Michael Catanzaro
08489deb06 Merge branch 'epoll-create' into 'main'
giounix-private: Fix macro for checking for epoll_create1()

See merge request GNOME/glib!4563
2025-03-20 12:33:50 +00:00
Philip Withnall
20f083ea7c giounix-private: Fix macro for checking for epoll_create1()
Like many things I touch, I broke this in
fd8ede0b66.

Spotted by Sebastian Wilhelmi in
fd8ede0b66 (note_2385263).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-20 11:12:58 +00:00