gvariant-serialiser: Check offsets array is initialised before using it

When piecewise validating the offset table for a variable sized array,
it’s possible that the offset table (`offsets.array`) won’t actually
have been set by `gvs_variable_sized_array_get_frame_offsets()` iff the
serialised `GVariant` is not in normal form.

Add an additional check to guard against this. This will result in an
empty child variant being returned, as with other error handling paths
in `gvs_variable_sized_array_get_child()`.

This is a true positive spotted by scan-build. Thanks, scan-build.

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

Helps: #1767
This commit is contained in:
Philip Withnall 2024-04-12 19:27:34 +01:00
parent 4b7f6ffe4c
commit 0814be8bef
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -762,7 +762,8 @@ gvs_variable_sized_array_get_child (GVariantSerialised value,
* Dont bother checking if the highest known-good offset is lower than the
* highest checked offset, as that means theres an invalid element at that
* index, so theres no need to check further. */
if (index_ > value.checked_offsets_up_to &&
if (offsets.array != NULL &&
index_ > value.checked_offsets_up_to &&
value.ordered_offsets_up_to == value.checked_offsets_up_to)
{
switch (offsets.offset_size)