From 7ba714ad7fe8256edfaad7d9a0f09aeb9611ca44 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 30 Jan 2003 04:20:44 +0000 Subject: 2003-01-30 Havoc Pennington * dbus/dbus-message.c: use message->byte_order instead of DBUS_COMPILER_BYTE_ORDER throughout. (dbus_message_create_header): pad header to align the start of the body of the message to 8-byte boundary * dbus/dbus-marshal.h: make all the demarshalers take const DBusString arguments. * dbus/dbus-message.c (_dbus_message_loader_return_buffer): validate message args here, so we don't have to do slow validation later, and so we catch bad messages as they are incoming. Also add better checks on header_len and body_len. Also fill in message->byte_order * dbus/dbus-string.c (_dbus_string_validate_utf8): new (not implemented properly) (_dbus_string_validate_nul): new function to check all-nul * dbus/dbus-marshal.c (_dbus_marshal_get_field_end_pos): rename get_arg_end_pos and remove all validation (_dbus_marshal_validate_arg): actually do validation here. --- dbus/dbus-string.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'dbus/dbus-string.c') diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index 9acf5cfb..f453dcb6 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -608,7 +608,7 @@ _dbus_string_align_length (DBusString *str, int delta; DBUS_STRING_PREAMBLE (str); _dbus_assert (alignment >= 1); - _dbus_assert (alignment <= 16); /* arbitrary */ + _dbus_assert (alignment <= 8); /* it has to be a bug if > 8 */ new_len = _DBUS_ALIGN_VALUE (real->len, alignment); @@ -1843,6 +1843,65 @@ _dbus_string_validate_ascii (const DBusString *str, return TRUE; } +/** + * Checks that the given range of the string + * is valid UTF-8. If the given range is not contained + * in the string, returns #FALSE. If the string + * contains any nul bytes in the given range, returns + * #FALSE. + * + * @todo right now just calls _dbus_string_validate_ascii() + * + * @param str the string + * @param start first byte index to check + * @param len number of bytes to check + * @returns #TRUE if the byte range exists and is all valid UTF-8 + */ +dbus_bool_t +_dbus_string_validate_utf8 (const DBusString *str, + int start, + int len) +{ + /* FIXME actually validate UTF-8 */ + return _dbus_string_validate_ascii (str, start, len); +} + +/** + * Checks that the given range of the string + * is all nul bytes. If the given range is + * not contained in the string, returns #FALSE. + * + * @param str the string + * @param start first byte index to check + * @param len number of bytes to check + * @returns #TRUE if the byte range exists and is all nul bytes + */ +dbus_bool_t +_dbus_string_validate_nul (const DBusString *str, + int start, + int len) +{ + const unsigned char *s; + const unsigned char *end; + DBUS_CONST_STRING_PREAMBLE (str); + _dbus_assert (start >= 0); + _dbus_assert (len >= 0); + + if ((start + len) > real->len) + return FALSE; + + s = real->str + start; + end = s + len; + while (s != end) + { + if (*s != '\0') + return FALSE; + ++s; + } + + return TRUE; +} + /** @} */ #ifdef DBUS_BUILD_TESTS -- cgit