Commit 4012b009 authored by Simon McVittie's avatar Simon McVittie
Browse files

Merge branch 'validate-when-sending-16338' into dbus-1.4


Reviewed-by: default avatarWill Thompson <will.thompson@collabora.co.uk>
parents d60cc351 a9cbeecf
......@@ -1221,6 +1221,8 @@ DEFINE_DBUS_NAME_CHECK(error_name)
DEFINE_DBUS_NAME_CHECK(bus_name)
/** define _dbus_check_is_valid_signature() */
DEFINE_DBUS_NAME_CHECK(signature)
/** define _dbus_check_is_valid_utf8() */
DEFINE_DBUS_NAME_CHECK(utf8)
/** @} */
......
......@@ -147,6 +147,8 @@ dbus_bool_t _dbus_validate_bus_name (const DBusString *str,
dbus_bool_t _dbus_validate_signature (const DBusString *str,
int start,
int len);
/* just to have a name consistent with the above: */
#define _dbus_validate_utf8(s,b,e) _dbus_string_validate_utf8 (s, b, e)
#ifdef DBUS_DISABLE_CHECKS
......@@ -193,6 +195,8 @@ DECLARE_DBUS_NAME_CHECK(error_name);
DECLARE_DBUS_NAME_CHECK(bus_name);
/** defines _dbus_check_is_valid_signature() */
DECLARE_DBUS_NAME_CHECK(signature);
/** defines _dbus_check_is_valid_utf8() */
DECLARE_DBUS_NAME_CHECK(utf8);
/** @} */
......
......@@ -2515,6 +2515,39 @@ dbus_message_iter_append_basic (DBusMessageIter *iter,
_dbus_return_val_if_fail (dbus_type_is_basic (type), FALSE);
_dbus_return_val_if_fail (value != NULL, FALSE);
#ifndef DBUS_DISABLE_CHECKS
switch (type)
{
const char * const *string_p;
const dbus_bool_t *bool_p;
case DBUS_TYPE_STRING:
string_p = value;
_dbus_return_val_if_fail (_dbus_check_is_valid_utf8 (*string_p), FALSE);
break;
case DBUS_TYPE_OBJECT_PATH:
string_p = value;
_dbus_return_val_if_fail (_dbus_check_is_valid_path (*string_p), FALSE);
break;
case DBUS_TYPE_SIGNATURE:
string_p = value;
_dbus_return_val_if_fail (_dbus_check_is_valid_signature (*string_p), FALSE);
break;
case DBUS_TYPE_BOOLEAN:
bool_p = value;
_dbus_return_val_if_fail (*bool_p == 0 || *bool_p == 1, FALSE);
break;
default:
{
/* nothing to check, all possible values are allowed */
}
}
#endif
if (!_dbus_message_iter_open_signature (real))
return FALSE;
......@@ -2627,6 +2660,19 @@ dbus_message_iter_append_fixed_array (DBusMessageIter *iter,
DBUS_MAXIMUM_ARRAY_LENGTH / _dbus_type_get_alignment (element_type),
FALSE);
#ifndef DBUS_DISABLE_CHECKS
if (element_type == DBUS_TYPE_BOOLEAN)
{
const dbus_bool_t * const *bools = value;
int i;
for (i = 0; i < n_elements; i++)
{
_dbus_return_val_if_fail ((*bools)[i] == 0 || (*bools)[i] == 1, FALSE);
}
}
#endif
ret = _dbus_type_writer_write_fixed_multi (&real->u.writer, element_type, value, n_elements);
return ret;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment