Commit Graph

30512 Commits

Author SHA1 Message Date
Philip Withnall
04a6ee3e9b Merge branch 'wip/3v1n0/gi-repository-leak-fixes' into 'main'
girepository/build: Actually use our compiler to generate GLib typelibs and fix parser leaks

See merge request GNOME/glib!4064
2024-05-16 23:15:16 +00:00
Philip Withnall
52e850d54c Merge branch 'ebassi/i18n-docs' into 'main'
Document the magic gettext macros in gi18n.h

Closes #3361

See merge request GNOME/glib!4071
2024-05-16 22:27:48 +00:00
Philip Withnall
5433bb23a0 Merge branch '3303-girepository-typelib-determinicity' into 'main'
girepository: Keep an ordered list of the loaded typelibs

Closes #3303

See merge request GNOME/glib!4033
2024-05-16 22:27:01 +00:00
Simon McVittie
434c105bbe gdbusconnection: Fix a misleading comment
While backporting CVE-2024-34397 fixes I noticed that this comment
claimed that the reference count is immutable after construction, which
is clearly not true. In fact the reference count is the only
mutable field.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:53:11 +01:00
Simon McVittie
510d0716be gdbus: Use symbolic constants for the most common D-Bus error names
To avoid adding a large block of macros to gdbusprivate.h, I've only
added a subset of the well-known error names. I chose to draw the
line by adding constants for the errors emitted via their string names
in GDBusConnection, but not for error names that are only mentioned
in `gdbuserror.c` or in tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
7c609f8142 gdbus: Use symbolic constants for interfaces from dbus-specification
Most D-Bus interfaces are domain-specific, but these interfaces from the
D-Bus Specification are intended to be commonly used in any context for
which they are found to be appropriate.

Most of these use `gdbusprivate.h`. One exception is that
`gio/tests/gdbus-example-*` redefine the constants locally: due to these
files' dual role as part of the unit tests and as sample code, it seems
desirable to ensure that they can still be compiled outside GLib.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
b4f8d4a5d5 gdbus: Use symbolic constants for the reserved Local path and interface
These are reserved by the D-Bus Specification.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
7401577074 gdbus: Move protocol constants from gdbusdaemon into gdbusprivate.h
These well-known flags and replies are part of the D-Bus Specification,
and also exist with the same names in libdbus header files.
Moving them into a private header means that unit tests like
gdbus-proxy-threads and gdbus-subscribe don't have to reinvent them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
b0e8612a3b gdbusdaemon: Use shared constants for message bus name, path, interface
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
131a061aca gdbus: Use symbolic constants for various references to the message bus
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
19223803f5 gdbus: Use symbolic constants to subscribe to message bus signals
Unlike the various functions to call D-Bus methods, these sort their
arguments in a non-obvious order (bus name, interface, signal, path),
presumably aiming to sort the most-likely-to-be-used arguments first.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
fe14968c0d gdbus: Use symbolic constants to call message bus methods
These function arguments are arranged in the obvious order from
conceptually largest to smallest: (bus name, path, interface, method).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:22 +01:00
Simon McVittie
2151a82007 gdbus tests: Fix a typo
This test was subscribing to the NameOwnerChanged signal with an
incorrect object path, so the callback would never be called. In this
particular case it doesn't actually matter, because the callback does
nothing anyway (the purpose of this particular test was to test that
the user-data is freed on unsubscription).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:22 +01:00
Marco Trevisan (Treviño)
b27fbf503b girepository/girparser,girmodule: Use a GPtrArray to hold the dependencies
It's just better than a list of strings for various reasons, but mostly
here it allows also to avoid copying the lists but making the
ownership clearer through references
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
2e2e606208 girparser: Simplify the ownership of context modules and parsed ones
There's no need to copy the list of modules and free it again, we can
just handle this by moving the modules to the parser promptly.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
23d3a5e859 girepository/girparser: Free the temporary context modules list when done
When we're about to return the found module we can just drop the list
of modules that we had previously copied in the temporary context
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
b59c3f73ee girepository/girparser: Free the parsed modules list elements
We were removing the modules themselves, but not the list items
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
6e38293fec girepository/girparser: Move dependencies ownership to each module
In this way the module can survive without that the parser is fully
alive.

At the moment a module has not a ref-count system, but this makes things
clearer when we return the module from a parser.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
9d65076eba girepository/girparser: Cleanup the node stack if anything destroyed it
If we've leftover nodes in the stack we should cleanup it
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
997d32e9cd girepository/girparser: Free the struct or union node if was not tracked
In case the node was pushed to a non-empty node stack, then we were not
tracking it in the entries list, and so nothing was freeing it on
destruction.

As per this, once parsing is done, we can free it or we'd leak.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
98dce8a1c6 girepository/girparser: Do not allocate the same node name twice
We were setting the node name two times, and the latter was overwriting
the first one, making impossible to free the value when destroying the
node
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
a359333dd0 girepository/girnode: Fully free the members and discriminators lists
We were removing the contents but not the lists themselves
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
4cdf53a15c girepository/girmodule: Cleanup the temporary dependencies string
It's used during build phase, as a temporary variable but never freed
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
6a4f8e5bb7 girepository/girmodule: Use clearer scope for the build struct
Allocate it only when needed avoiding manual memset
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
05f606f3c5 girepository/girmodule: Cleanup the build stack once we've done
The stack is allocated with a list that we need to free once done
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
6f69fd53df girepository/girnode: Simplify the ownership fo the serialized type string 2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
9f4b97bb92 girepository/girmodule: Cleanup the builder types hash keys
We were adding new keys but never removing them, so use the proper
destroy notify for them and clarify the ownership on the caller.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
1b8ef05321 girepository/girmodule: Free the version, shared library and c prefix
Those strings are explicitly duplicated but never free'd
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
47cf6387ad girepository/compiler: Free the parser when not needed
The compiler code was full of leaks and nothing really checked on them.

While it's not a big deal per se, per the nature of it, it's still
better to ensure that memory management is well done so that there are
no problems when using it with sanitizers.

So, the source of the problems was not freeing the parser, but that
wasn't enough, more to come...
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
311367620a girepository/build: Actually use our compiler to generate GLib typelibs
We are overriding the default g-ir-compiler for local usage, but this
is not actually happen since that's computed while parsing introspection

So generate the compiler as first thing, then in case handle the
introspection data
2024-05-16 22:51:12 +01:00
Philip Withnall
03248e7b18
girepository: Make gi_repository_get_loaded_namespaces() deterministic
As with the previous two commits, the results of calling
`gi_repository_get_loaded_namespaces()` were previously
non-deterministic due to being generated by iterating over a hash table,
which has a non-deterministic iteration order.

Fix that by using the new `ordered_typelibs` and `ordered_lazy_typelibs`
arrays to provide deterministic ordering.

At the same time, significantly reduce the number of allocations needed
to build the return value — previously the results would be built as a
linked list before being turned into an array. The linked list is now
banished to history.

Add some more unit tests to maximise test coverage of this method.

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

Fixes: #3303
2024-05-16 22:47:49 +01:00
Philip Withnall
0d199d6199
girepository: Make gi_repository_find_by_error_domain() deterministic
As with the previous commit, finding a `GIBaseInfo` matching the given
error domain was non-deterministic because it iterated through a hash
table of typelibs. Hash table iteration is non-deterministic.

Change the method to instead use the `ordered_typelibs` and
`ordered_lazy_typelibs` arrays to give deterministic iteration order.

Add a unit test, although it can’t test the interesting case of an error
domain which is present in both `GioUnix`/`GioWin32` and `Gio`, because
no such error domain exists.

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

Helps: #3303
2024-05-16 22:47:42 +01:00
Philip Withnall
81b16a88d1
girepository: Make gi_repository_find_by_gtype() deterministic
When faced with a `GType` which is present in multiple typelibs, the old
implementation was not deterministic, as it iterated over a hash table
of typelibs. The iteration order of a hash table is not deterministic.

Use the new `ordered_typelibs` and `ordered_lazy_typelibs` arrays to
iterate instead, making the order deterministic.

Add a unit test to check this. In particular, to check that symbols
which are present in both `Gio` and `GioUnix` are correctly resolved as
being from `GioUnix`.

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

Helps: #3303
2024-05-16 22:47:35 +01:00
Philip Withnall
14d196a6c1
gitypelib: Fix iterating through typelib prefixes
The iteration code used `g_string_overwrite_len()` to try and simplify
buffer allocation and growth, but seemingly forgot to handle the fact
that it doesn’t nul-terminate what it overwrites: the method is intended
to be used to splice bits into longer strings, not to overwrite an
entire nul-terminated string.

This meant that when iterating over a comma-separated `c_prefix` like
`GUnix,G`, on the second iteration `g_string_overwrite_len()` would be
used to write `G` into index 0 of the already-set `GUnix` string in the
buffer, leading to the first iteration happening all over again and the
`G` prefix being ignored.

This led to symbols failing to be matched to the `GioUnix` typelib, even
though they should have been.

This will be checked by a test in the following commit.

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

Helps: #3303
2024-05-16 22:47:29 +01:00
Philip Withnall
e0533125d3
girepository: Fix a typo in a code comment
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 22:47:23 +01:00
Philip Withnall
1ed2cf63ed
girepository: Keep an ordered list of the loaded typelibs
There are various places where the set of typelibs is iterated over or
returned in an ordered way. In order to keep results deterministic and
reproducible, we need to keep this set ordered.

Keep a `GPtrArray` of the typelibs (one for fully-loaded ones and one
for lazy ones) alongside the existing hash tables. This will be used for
iteration in the next few commits.

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

Helps: #3303
2024-05-16 22:47:16 +01:00
Philip Withnall
3807fae17e Fix consistency of code blocks
Use the appropriate code blocks for strings, file names,
and extensions.
2024-05-16 22:45:53 +01:00
Emmanuele Bassi
91a08c01f3 Document the magic gettext macros in gi18n.h
These symbols are barely introspectable, which means they have to be
collected into the existing i18n content document.

Fixes: #3361
2024-05-16 22:45:53 +01:00
Michael Catanzaro
1bbf500fb8 Merge branch 'wip/pwithnall/clang-discarded-qualifiers' into 'main'
tests: Fix clang compilation failure due to unrecognised option in pragma

See merge request GNOME/glib!4078
2024-05-16 16:29:27 +00:00
Philip Withnall
4d2e0df9ee Merge branch 'ebassi/c99-boolean-constants' into 'main'
Alias TRUE and FALSE to C99's true and false

Closes #3326

See merge request GNOME/glib!4001
2024-05-16 12:50:08 +00:00
Philip Withnall
e87b659905
ci: Temporarily run the FreeBSD on a schedule rather than every commit
The runner is currently offline and we can’t have that blocking
development.

See: https://gitlab.gnome.org/Infrastructure/Infrastructure/-/issues/1503

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 12:51:04 +01:00
Philip Withnall
3be537a2a8
tests: Fix clang compilation failure due to unrecognised option in pragma
Sigh.

```
../glib/tests/atomic.c:139:32: error: unknown warning group '-Wdiscarded-qualifiers', ignored [-Werror,-Wunknown-warning-option]
\#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
                               ^
1 error generated.
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 12:50:57 +01:00
Michael Catanzaro
b9490a499a Merge branch '3366-menu-exporter-error-handling' into 'main'
gmenuexporter: Fix a NULL pointer dereference on an error handling path

Closes #3366

See merge request GNOME/glib!4073
2024-05-15 14:55:18 +00:00
Michael Catanzaro
412805357a Merge branch 'update-fedora-ci-image' into 'main'
ci: Update Fedora CI image to Fedora 39

See merge request GNOME/glib!4075
2024-05-15 14:27:02 +00:00
Philip Withnall
7a7137838e
gactiongroupexporter: Fix memory problems on an error handling path
Almost identically to the previous commit, fix a similar latent bug in
`g_dbus_connection_export_action_group()`, which was not ready to handle
the fledgling `GActionGroupExporter` being freed early on an error
handling path.

See the previous commit message for details of the approach.

This includes a unit test.

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

Fixes: #3366
2024-05-15 14:00:09 +01:00
Philip Withnall
91fb6ea0e1 Merge branch 'docs-string-utils-header' into 'main'
docs: Fix string-utils paragraph heading

See merge request GNOME/glib!4068
2024-05-15 12:39:54 +00:00
Philip Withnall
21fa4ea91b
ci: Update Fedora CI image to Fedora 39
Fedora 37 is out of support so, as per our policy, update the CI image
to the oldest still-supported release, which is 39.

Update the mingw CI image too, as it’s built on top of the Fedora one.

Update the supported platforms documentation (and fix the Debian version
listed there to match what’s currently in CI, which is up to date).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-15 13:27:47 +01:00
Philip Withnall
aad1646e6f Merge branch 'structcleanup' into 'main'
Remove unused struct

See merge request GNOME/glib!4067
2024-05-15 12:19:38 +00:00
Philip Withnall
797f9c5157 Merge branch 'girepository-bitfield' into 'main'
girepository: Don't assume a bitfield has a fixed size

Closes #3355

See merge request GNOME/glib!4065
2024-05-15 11:53:51 +00:00
Philip Withnall
df2c5d925a
gmenuexporter: Fix a NULL pointer dereference on an error handling path
This latent bug wasn’t triggered until commit 3f30ec86c (or its
cherry-pick onto `glib-2-80`, 747e3af99, which was first released in
2.80.1).

That change means that `g_menu_exporter_free()` is now called on the
registration failure path by `g_dbus_connection_register_object()`
before it returns. The caller then tries to call `g_slice_free()` on the
exporter again. The call to `g_menu_exporter_free()` tries to
dereference/free members of the exporter which it expects to be
initialised — but because this is happening in an error handling path,
they are not initialised.

If it were to get any further, the `g_slice_free()` would then be a
double-free on the exporter allocation.

Fix that by making `g_menu_exporter_free()` robust to some of the
exporter members being `NULL`, and moving some of the initialisation
code higher in `g_dbus_connection_export_menu_model()`, and removing the
duplicate free code on the error handling path.

This includes a unit test.

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

Fixes: #3366
2024-05-15 12:52:38 +01:00