diff options
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r-- | dbus/dbus-string.c | 88 |
1 files changed, 84 insertions, 4 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index f4f7a2ad..848135fc 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -2846,7 +2846,7 @@ _dbus_string_validate_nul (const DBusString *str, } /** - * Checks that the given range of the string is a valid message name + * Checks that the given range of the string is a valid interface name * in the D-BUS protocol. This includes a length restriction, etc., * see the specification. It does not validate UTF-8, that has to be * done separately for now. @@ -2860,9 +2860,9 @@ _dbus_string_validate_nul (const DBusString *str, * @returns #TRUE if the byte range exists and is a valid name */ dbus_bool_t -_dbus_string_validate_name (const DBusString *str, - int start, - int len) +_dbus_string_validate_interface (const DBusString *str, + int start, + int len) { const unsigned char *s; const unsigned char *end; @@ -2902,6 +2902,86 @@ _dbus_string_validate_name (const DBusString *str, return TRUE; } +/** + * Checks that the given range of the string is a valid member name + * in the D-BUS protocol. This includes a length restriction, etc., + * see the specification. It does not validate UTF-8, that has to be + * done separately for now. + * + * @todo this is inconsistent with most of DBusString in that + * it allows a start,len range that isn't in the string. + * + * @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 a valid name + */ +dbus_bool_t +_dbus_string_validate_member (const DBusString *str, + int start, + int len) +{ + const unsigned char *s; + const unsigned char *end; + dbus_bool_t saw_dot; + + DBUS_CONST_STRING_PREAMBLE (str); + _dbus_assert (start >= 0); + _dbus_assert (len >= 0); + _dbus_assert (start <= real->len); + + if (len > real->len - start) + return FALSE; + + if (len > DBUS_MAXIMUM_NAME_LENGTH) + return FALSE; + + if (len == 0) + return FALSE; + + saw_dot = FALSE; + s = real->str + start; + end = s + len; + while (s != end) + { + if (*s == '.') + { + saw_dot = TRUE; + break; + } + + ++s; + } + + /* No dot allowed in member names */ + if (saw_dot) + return FALSE; + + return TRUE; +} + +/** + * Checks that the given range of the string is a valid error name + * in the D-BUS protocol. This includes a length restriction, etc., + * see the specification. It does not validate UTF-8, that has to be + * done separately for now. + * + * @todo this is inconsistent with most of DBusString in that + * it allows a start,len range that isn't in the string. + * + * @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 a valid name + */ +dbus_bool_t +_dbus_string_validate_error_name (const DBusString *str, + int start, + int len) +{ + /* Same restrictions as interface name at the moment */ + return _dbus_string_validate_interface (str, start, len); +} /** * Checks that the given range of the string is a valid service name |