Skip to content

Conversation

@jlebon
Copy link
Contributor

@jlebon jlebon commented Apr 28, 2025

A GVariant may require 0 bytes to serialize. In which case, data_size will be 0 and we'll call g_malloc0 (0) which returns NULL.

The data argument of g_variant_store is declared as non-nullable, so we shouldn't pass it NULL. In older glib versions, this wasn't explicitly checked and it still transparently worked for our case because there was nothing to actually serialize. Starting from v2.84.1, a precondition was added:

https://gitlab.gnome.org/GNOME/glib/-/commit/39c05b13123b12622ee2c93c170dbf20b573f6ac

Let's respect the API here and stop calling the function if it's not needed.

Note that g_variant_new_from_data() supports being passed NULL and 0 for the data and size arguments.

A GVariant may require 0 bytes to serialize. In which case, `data_size`
will be 0 and we'll call `g_malloc0 (0)` which returns `NULL`.

The `data` argument of `g_variant_store` is declared as non-nullable,
so we shouldn't pass it `NULL`. In older glib versions, this wasn't
explicitly checked and it still transparently worked for our case
because there was nothing to actually serialize. Starting from v2.84.1,
a precondition was added:

https://gitlab.gnome.org/GNOME/glib/-/commit/39c05b13123b12622ee2c93c170dbf20b573f6ac

Let's respect the API here and stop calling the function if it's not
needed.

Note that `g_variant_new_from_data()` supports being passed `NULL` and 0
for the data and size arguments.
@jlebon
Copy link
Contributor Author

jlebon commented Apr 28, 2025

See also discussion in https://gitlab.gnome.org/GNOME/glib/-/issues/3675.

@sgallagher
Copy link
Collaborator

This patch and #624 seem to disagree about what the input value is. Do we have a non-NULL GVariant with zero-length data, or do we have a NULL GVariant?

@jlebon
Copy link
Contributor Author

jlebon commented Apr 28, 2025

This patch and #624 seem to disagree about what the input value is. Do we have a non-NULL GVariant with zero-length data, or do we have a NULL GVariant?

Missed that. Replied there.

@ppisar
Copy link
Collaborator

ppisar commented Apr 28, 2025

Excuse me, where is "the data argument of g_variant_store declared as non-nullable"? My glib/gvariant.h from 2.84.1 does not mention it as well as the https://docs.gtk.org/glib/method.Variant.store.html documentation.

The modulemd_variant_deep_copy() is a private function and it is only used when setting XMD for a module, e.g with modulemd_module_stream_v2_set_xmd(). I feel this fix needs to be accompanied with a test.

@jlebon
Copy link
Contributor Author

jlebon commented Apr 28, 2025

Excuse me, where is "the data argument of g_variant_store declared as non-nullable"? My glib/gvariant.h from 2.84.1 does not mention it as well as the docs.gtk.org/glib/method.Variant.store.html documentation.

Hmm, I'm not sure if's supposed to be rendered on that docs page, but the annotation is definitely there: https://gitlab.gnome.org/GNOME/glib/blob/490438c41624d7753f17d3c6e3eb74bcdea1c68b/glib/gvariant-core.c#L1397. And looks like it's been there for quite a while AFAICT.

The modulemd_variant_deep_copy() is a private function and it is only used when setting XMD for a module, e.g with modulemd_module_stream_v2_set_xmd(). I feel this fix needs to be accompanied with a test.

That's reasonable. I don't have the cycles to add a test for this unfortunately. The way I verified this is simply that it no longer logs the assertion failure (and e.g. dnf module list still worked fine).

@ppisar
Copy link
Collaborator

ppisar commented Apr 29, 2025

Thanks for the explanation. I verified your fix and pushed a test on top of this commit. I will merge it once CI finishes.

@ppisar ppisar force-pushed the pr/deep-copy-null branch from 732d483 to 9a2c6fb Compare April 29, 2025 14:41
@ppisar ppisar merged commit ca21b17 into fedora-modularity:main Apr 30, 2025
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants