From b10209fa73c0eb5d5475910f0b9b7c38ab69c873 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 5 May 2010 13:31:38 +0200 Subject: [PATCH 3/5] Check that a maybe has none or one element --- dbus/dbus-message.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 7f671ce..bf22017 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -887,6 +887,14 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, _dbus_assert (i == n_elements); _dbus_assert (str_array[i] == NULL); + if (spec_type == DBUS_TYPE_MAYBE && _DBUS_UNLIKELY (n_elements > 1)) + { + dbus_set_error (error, DBUS_ERROR_INCONSISTENT_MESSAGE, + "Maybe \"%s\" contains multiple elements\n", + _dbus_type_to_string (spec_element_type)); + goto out; + } + *str_array_p = str_array; *n_elements_p = n_elements; } @@ -2686,6 +2694,10 @@ dbus_message_iter_open_container (DBusMessageIter *iter, (contained_signature == NULL || _dbus_check_is_valid_signature (contained_signature)), FALSE); + /* the contained signature of a maybe must contain exactly one element */ + _dbus_return_val_if_fail (((type == DBUS_TYPE_MAYBE && + dbus_signature_validate_single (contained_signature, NULL)) + || type != DBUS_TYPE_MAYBE), FALSE); if (!_dbus_message_iter_open_signature (real)) return FALSE; -- 1.7.3.2