gdbusmessage: Disallow empty structures/tuples in D-Bus messages

They are disallowed in the specification:
https://dbus.freedesktop.org/doc/dbus-specification.html#container-types

Helps: #2557
This commit is contained in:
Sebastian Wilhelmi
2022-01-06 21:04:56 +00:00
committed by Philip Withnall
parent 77233f6f07
commit 6499ad5356
2 changed files with 107 additions and 0 deletions

View File

@@ -1907,6 +1907,16 @@ parse_value_from_blob (GMemoryBuffer *buf,
g_variant_builder_init (&builder, type);
element_type = g_variant_type_first (type);
if (!element_type)
{
g_variant_builder_clear (&builder);
g_set_error_literal (&local_error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Empty structures (tuples) are not allowed in D-Bus"));
goto fail;
}
while (element_type != NULL)
{
GVariant *item;
@@ -2617,6 +2627,15 @@ append_value_to_blob (GVariant *value,
default:
if (g_variant_type_is_dict_entry (type) || g_variant_type_is_tuple (type))
{
if (!g_variant_type_first (type))
{
g_set_error_literal (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Empty structures (tuples) are not allowed in D-Bus"));
goto fail;
}
padding_added = ensure_output_padding (mbuf, 8);
if (value != NULL)
{