1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-marshal-validate.c Validation routines for marshaled data
4 * Copyright (C) 2005 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "dbus-internals.h"
25 #include "dbus-marshal-validate.h"
26 #include "dbus-marshal-recursive.h"
27 #include "dbus-marshal-basic.h"
28 #include "dbus-signature.h"
29 #include "dbus-string.h"
32 * @addtogroup DBusMarshal
38 * Verifies that the range of type_str from type_pos to type_end is a
39 * valid signature. If this function returns #TRUE, it will be safe
40 * to iterate over the signature with a types-only #DBusTypeReader.
41 * The range passed in should NOT include the terminating
42 * nul/DBUS_TYPE_INVALID.
44 * @param type_str the string
45 * @param type_pos where the typecodes start
46 * @param len length of typecodes
47 * @returns #DBUS_VALID if valid, reason why invalid otherwise
50 _dbus_validate_signature_with_reason (const DBusString *type_str,
54 const unsigned char *p;
55 const unsigned char *end;
63 DBusList *element_count_stack;
66 element_count_stack = NULL;
68 if (!_dbus_list_append (&element_count_stack, _DBUS_INT_TO_POINTER (0)))
70 result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
74 _dbus_assert (type_str != NULL);
75 _dbus_assert (type_pos < _DBUS_INT32_MAX - len);
76 _dbus_assert (len >= 0);
77 _dbus_assert (type_pos >= 0);
79 if (len > DBUS_MAXIMUM_SIGNATURE_LENGTH)
81 result = DBUS_INVALID_SIGNATURE_TOO_LONG;
85 p = _dbus_string_get_const_data_len (type_str, type_pos, 0);
87 end = _dbus_string_get_const_data_len (type_str, type_pos + len, 0);
91 last = DBUS_TYPE_INVALID;
98 case DBUS_TYPE_BOOLEAN:
100 case DBUS_TYPE_UINT16:
101 case DBUS_TYPE_INT32:
102 case DBUS_TYPE_UINT32:
103 case DBUS_TYPE_INT64:
104 case DBUS_TYPE_UINT64:
105 case DBUS_TYPE_DOUBLE:
106 case DBUS_TYPE_STRING:
107 case DBUS_TYPE_OBJECT_PATH:
108 case DBUS_TYPE_SIGNATURE:
109 case DBUS_TYPE_VARIANT:
112 case DBUS_TYPE_ARRAY:
114 if (array_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH)
116 result = DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION;
121 case DBUS_STRUCT_BEGIN_CHAR:
124 if (struct_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH)
126 result = DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION;
130 if (!_dbus_list_append (&element_count_stack,
131 _DBUS_INT_TO_POINTER (0)))
133 result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
139 case DBUS_STRUCT_END_CHAR:
140 if (struct_depth == 0)
142 result = DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED;
146 if (last == DBUS_STRUCT_BEGIN_CHAR)
148 result = DBUS_INVALID_STRUCT_HAS_NO_FIELDS;
152 _dbus_list_pop_last (&element_count_stack);
157 case DBUS_DICT_ENTRY_BEGIN_CHAR:
158 if (last != DBUS_TYPE_ARRAY)
160 result = DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY;
164 dict_entry_depth += 1;
166 if (dict_entry_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH)
168 result = DBUS_INVALID_EXCEEDED_MAXIMUM_DICT_ENTRY_RECURSION;
172 if (!_dbus_list_append (&element_count_stack,
173 _DBUS_INT_TO_POINTER (0)))
175 result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
181 case DBUS_DICT_ENTRY_END_CHAR:
182 if (dict_entry_depth == 0)
184 result = DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED;
188 dict_entry_depth -= 1;
191 _DBUS_POINTER_TO_INT (_dbus_list_pop_last (&element_count_stack));
193 if (element_count != 2)
195 if (element_count == 0)
196 result = DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS;
197 else if (element_count == 1)
198 result = DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD;
200 result = DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS;
206 case DBUS_TYPE_STRUCT: /* doesn't appear in signatures */
207 case DBUS_TYPE_DICT_ENTRY: /* ditto */
209 result = DBUS_INVALID_UNKNOWN_TYPECODE;
213 if (*p != DBUS_TYPE_ARRAY &&
214 *p != DBUS_DICT_ENTRY_BEGIN_CHAR &&
215 *p != DBUS_STRUCT_BEGIN_CHAR)
218 _DBUS_POINTER_TO_INT (_dbus_list_pop_last (&element_count_stack));
222 if (!_dbus_list_append (&element_count_stack,
223 _DBUS_INT_TO_POINTER (element_count)))
225 result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
232 if (*p == DBUS_TYPE_ARRAY && p != end)
236 if (*p1 == DBUS_STRUCT_END_CHAR ||
237 *p1 == DBUS_DICT_ENTRY_END_CHAR)
239 result = DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE;
249 if (last == DBUS_DICT_ENTRY_BEGIN_CHAR &&
250 _dbus_type_is_valid (*p) &&
251 !dbus_type_is_basic (*p))
253 result = DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE;
264 result = DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE;
268 if (struct_depth > 0)
270 result = DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED;
274 if (dict_entry_depth > 0)
276 result = DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED;
280 _dbus_assert (last != DBUS_TYPE_ARRAY);
281 _dbus_assert (last != DBUS_STRUCT_BEGIN_CHAR);
282 _dbus_assert (last != DBUS_DICT_ENTRY_BEGIN_CHAR);
287 _dbus_list_clear (&element_count_stack);
292 validate_body_helper (DBusTypeReader *reader,
294 dbus_bool_t walk_reader_to_end,
295 const unsigned char *p,
296 const unsigned char *end,
297 const unsigned char **new_p)
301 while ((current_type = _dbus_type_reader_get_current_type (reader)) != DBUS_TYPE_INVALID)
303 const unsigned char *a;
307 _dbus_verbose (" validating value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
308 _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
312 /* Guarantee that p has one byte to look at */
314 return DBUS_INVALID_NOT_ENOUGH_DATA;
316 switch (current_type)
322 case DBUS_TYPE_BOOLEAN:
323 case DBUS_TYPE_INT16:
324 case DBUS_TYPE_UINT16:
325 case DBUS_TYPE_INT32:
326 case DBUS_TYPE_UINT32:
327 case DBUS_TYPE_INT64:
328 case DBUS_TYPE_UINT64:
329 case DBUS_TYPE_DOUBLE:
330 alignment = _dbus_type_get_alignment (current_type);
331 a = _DBUS_ALIGN_ADDRESS (p, alignment);
333 return DBUS_INVALID_NOT_ENOUGH_DATA;
337 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
341 if (current_type == DBUS_TYPE_BOOLEAN)
343 dbus_uint32_t v = _dbus_unpack_uint32 (byte_order,
345 if (!(v == 0 || v == 1))
346 return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE;
352 case DBUS_TYPE_ARRAY:
353 case DBUS_TYPE_STRING:
354 case DBUS_TYPE_OBJECT_PATH:
356 dbus_uint32_t claimed_len;
358 a = _DBUS_ALIGN_ADDRESS (p, 4);
360 return DBUS_INVALID_NOT_ENOUGH_DATA;
364 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
368 claimed_len = _dbus_unpack_uint32 (byte_order, p);
371 /* p may now be == end */
372 _dbus_assert (p <= end);
374 if (current_type == DBUS_TYPE_ARRAY)
376 int array_elem_type = _dbus_type_reader_get_element_type (reader);
377 alignment = _dbus_type_get_alignment (array_elem_type);
378 p = _DBUS_ALIGN_ADDRESS (p, alignment);
381 if (claimed_len > (unsigned long) (end - p))
382 return DBUS_INVALID_LENGTH_OUT_OF_BOUNDS;
384 if (current_type == DBUS_TYPE_OBJECT_PATH)
387 _dbus_string_init_const_len (&str, p, claimed_len);
388 if (!_dbus_validate_path (&str, 0,
389 _dbus_string_get_length (&str)))
390 return DBUS_INVALID_BAD_PATH;
394 else if (current_type == DBUS_TYPE_STRING)
397 _dbus_string_init_const_len (&str, p, claimed_len);
398 if (!_dbus_string_validate_utf8 (&str, 0,
399 _dbus_string_get_length (&str)))
400 return DBUS_INVALID_BAD_UTF8_IN_STRING;
404 else if (current_type == DBUS_TYPE_ARRAY && claimed_len > 0)
407 DBusValidity validity;
408 const unsigned char *array_end;
410 if (claimed_len > DBUS_MAXIMUM_ARRAY_LENGTH)
411 return DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM;
413 /* Remember that the reader is types only, so we can't
414 * use it to iterate over elements. It stays the same
417 _dbus_type_reader_recurse (reader, &sub);
419 array_end = p + claimed_len;
421 while (p < array_end)
423 /* FIXME we are calling a function per array element! very bad
424 * need if (dbus_type_is_fixed(elem_type)) here to just skip
425 * big blocks of ints/bytes/etc.
428 validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
429 if (validity != DBUS_VALID)
434 return DBUS_INVALID_ARRAY_LENGTH_INCORRECT;
437 /* check nul termination */
438 if (current_type != DBUS_TYPE_ARRAY)
441 return DBUS_INVALID_NOT_ENOUGH_DATA;
444 return DBUS_INVALID_STRING_MISSING_NUL;
450 case DBUS_TYPE_SIGNATURE:
452 dbus_uint32_t claimed_len;
454 DBusValidity validity;
459 /* 1 is for nul termination */
460 if (claimed_len + 1 > (unsigned long) (end - p))
461 return DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
463 _dbus_string_init_const_len (&str, p, claimed_len);
465 _dbus_validate_signature_with_reason (&str, 0,
466 _dbus_string_get_length (&str));
468 if (validity != DBUS_VALID)
473 _dbus_assert (p < end);
474 if (*p != DBUS_TYPE_INVALID)
475 return DBUS_INVALID_SIGNATURE_MISSING_NUL;
479 _dbus_verbose ("p = %p end = %p claimed_len %u\n", p, end, claimed_len);
483 case DBUS_TYPE_VARIANT:
485 /* 1 byte sig len, sig typecodes, align to
486 * contained-type-boundary, values.
489 /* In addition to normal signature validation, we need to be sure
490 * the signature contains only a single (possibly container) type.
492 dbus_uint32_t claimed_len;
495 DBusValidity validity;
496 int contained_alignment;
504 if (claimed_len + 1 > (unsigned long) (end - p))
505 return DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
507 _dbus_string_init_const_len (&sig, p, claimed_len);
508 reason = _dbus_validate_signature_with_reason (&sig, 0,
509 _dbus_string_get_length (&sig));
510 if (!(reason == DBUS_VALID))
512 if (reason == DBUS_VALIDITY_UNKNOWN_OOM_ERROR)
515 return DBUS_INVALID_VARIANT_SIGNATURE_BAD;
520 if (*p != DBUS_TYPE_INVALID)
521 return DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL;
524 contained_type = _dbus_first_type_in_signature (&sig, 0);
525 if (contained_type == DBUS_TYPE_INVALID)
526 return DBUS_INVALID_VARIANT_SIGNATURE_EMPTY;
528 contained_alignment = _dbus_type_get_alignment (contained_type);
530 a = _DBUS_ALIGN_ADDRESS (p, contained_alignment);
532 return DBUS_INVALID_NOT_ENOUGH_DATA;
536 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
540 _dbus_type_reader_init_types_only (&sub, &sig, 0);
542 _dbus_assert (_dbus_type_reader_get_current_type (&sub) != DBUS_TYPE_INVALID);
544 validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
545 if (validity != DBUS_VALID)
548 if (_dbus_type_reader_next (&sub))
549 return DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES;
551 _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_INVALID);
555 case DBUS_TYPE_DICT_ENTRY:
556 case DBUS_TYPE_STRUCT:
559 DBusValidity validity;
561 a = _DBUS_ALIGN_ADDRESS (p, 8);
563 return DBUS_INVALID_NOT_ENOUGH_DATA;
567 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
571 _dbus_type_reader_recurse (reader, &sub);
573 validity = validate_body_helper (&sub, byte_order, TRUE, p, end, &p);
574 if (validity != DBUS_VALID)
580 _dbus_assert_not_reached ("invalid typecode in supposedly-validated signature");
585 _dbus_verbose (" validated value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
586 _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
592 _dbus_verbose ("not enough data!!! p = %p end = %p end-p = %d\n",
593 p, end, (int) (end - p));
594 return DBUS_INVALID_NOT_ENOUGH_DATA;
597 if (walk_reader_to_end)
598 _dbus_type_reader_next (reader);
610 * Verifies that the range of value_str from value_pos to value_end is
611 * a legitimate value of type expected_signature. If this function
612 * returns #TRUE, it will be safe to iterate over the values with
613 * #DBusTypeReader. The signature is assumed to be already valid.
615 * If bytes_remaining is not #NULL, then leftover bytes will be stored
616 * there and #DBUS_VALID returned. If it is #NULL, then
617 * #DBUS_INVALID_TOO_MUCH_DATA will be returned if bytes are left
620 * @param expected_signature the expected types in the value_str
621 * @param expected_signature_start where in expected_signature is the signature
622 * @param byte_order the byte order
623 * @param bytes_remaining place to store leftover bytes
624 * @param value_str the string containing the body
625 * @param value_pos where the values start
626 * @param len length of values after value_pos
627 * @returns #DBUS_VALID if valid, reason why invalid otherwise
630 _dbus_validate_body_with_reason (const DBusString *expected_signature,
631 int expected_signature_start,
633 int *bytes_remaining,
634 const DBusString *value_str,
638 DBusTypeReader reader;
639 const unsigned char *p;
640 const unsigned char *end;
641 DBusValidity validity;
643 _dbus_assert (len >= 0);
644 _dbus_assert (value_pos >= 0);
645 _dbus_assert (value_pos <= _dbus_string_get_length (value_str) - len);
647 _dbus_verbose ("validating body from pos %d len %d sig '%s'\n",
648 value_pos, len, _dbus_string_get_const_data_len (expected_signature,
649 expected_signature_start,
652 _dbus_type_reader_init_types_only (&reader,
653 expected_signature, expected_signature_start);
655 p = _dbus_string_get_const_data_len (value_str, value_pos, len);
658 validity = validate_body_helper (&reader, byte_order, TRUE, p, end, &p);
659 if (validity != DBUS_VALID)
664 *bytes_remaining = end - p;
668 return DBUS_INVALID_TOO_MUCH_DATA;
671 _dbus_assert (p == end);
677 * Determine wether the given character is valid as the first character
680 #define VALID_INITIAL_NAME_CHARACTER(c) \
681 ( ((c) >= 'A' && (c) <= 'Z') || \
682 ((c) >= 'a' && (c) <= 'z') || \
686 * Determine wether the given character is valid as a second or later
687 * character in a name
689 #define VALID_NAME_CHARACTER(c) \
690 ( ((c) >= '0' && (c) <= '9') || \
691 ((c) >= 'A' && (c) <= 'Z') || \
692 ((c) >= 'a' && (c) <= 'z') || \
696 * Checks that the given range of the string is a valid object path
697 * name in the D-Bus protocol. Part of the validation ensures that
698 * the object path contains only ASCII.
700 * @todo this is inconsistent with most of DBusString in that
701 * it allows a start,len range that extends past the string end.
703 * @todo change spec to disallow more things, such as spaces in the
706 * @param str the string
707 * @param start first byte index to check
708 * @param len number of bytes to check
709 * @returns #TRUE if the byte range exists and is a valid name
712 _dbus_validate_path (const DBusString *str,
716 const unsigned char *s;
717 const unsigned char *end;
718 const unsigned char *last_slash;
720 _dbus_assert (start >= 0);
721 _dbus_assert (len >= 0);
722 _dbus_assert (start <= _dbus_string_get_length (str));
724 if (len > _dbus_string_get_length (str) - start)
730 s = _dbus_string_get_const_data (str) + start;
742 if ((s - last_slash) < 2)
743 return FALSE; /* no empty path components allowed */
749 if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
756 if ((end - last_slash) < 2 &&
758 return FALSE; /* trailing slash not allowed unless the string is "/" */
764 * Checks that the given range of the string is a valid interface name
765 * in the D-Bus protocol. This includes a length restriction and an
766 * ASCII subset, see the specification.
768 * @todo this is inconsistent with most of DBusString in that
769 * it allows a start,len range that extends past the string end.
771 * @param str the string
772 * @param start first byte index to check
773 * @param len number of bytes to check
774 * @returns #TRUE if the byte range exists and is a valid name
777 _dbus_validate_interface (const DBusString *str,
781 const unsigned char *s;
782 const unsigned char *end;
783 const unsigned char *iface;
784 const unsigned char *last_dot;
786 _dbus_assert (start >= 0);
787 _dbus_assert (len >= 0);
788 _dbus_assert (start <= _dbus_string_get_length (str));
790 if (len > _dbus_string_get_length (str) - start)
793 if (len > DBUS_MAXIMUM_NAME_LENGTH)
800 iface = _dbus_string_get_const_data (str) + start;
804 /* check special cases of first char so it doesn't have to be done
805 * in the loop. Note we know len > 0
807 if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
809 else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
818 if (_DBUS_UNLIKELY ((s + 1) == end))
820 else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*(s + 1))))
823 ++s; /* we just validated the next char, so skip two */
825 else if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
833 if (_DBUS_UNLIKELY (last_dot == NULL))
840 * Checks that the given range of the string is a valid member name
841 * in the D-Bus protocol. This includes a length restriction, etc.,
842 * see the specification.
844 * @todo this is inconsistent with most of DBusString in that
845 * it allows a start,len range that extends past the string end.
847 * @param str the string
848 * @param start first byte index to check
849 * @param len number of bytes to check
850 * @returns #TRUE if the byte range exists and is a valid name
853 _dbus_validate_member (const DBusString *str,
857 const unsigned char *s;
858 const unsigned char *end;
859 const unsigned char *member;
861 _dbus_assert (start >= 0);
862 _dbus_assert (len >= 0);
863 _dbus_assert (start <= _dbus_string_get_length (str));
865 if (len > _dbus_string_get_length (str) - start)
868 if (len > DBUS_MAXIMUM_NAME_LENGTH)
874 member = _dbus_string_get_const_data (str) + start;
878 /* check special cases of first char so it doesn't have to be done
879 * in the loop. Note we know len > 0
882 if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
889 if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
901 * Checks that the given range of the string is a valid error name
902 * in the D-Bus protocol. This includes a length restriction, etc.,
903 * see the specification.
905 * @todo this is inconsistent with most of DBusString in that
906 * it allows a start,len range that extends past the string end.
908 * @param str the string
909 * @param start first byte index to check
910 * @param len number of bytes to check
911 * @returns #TRUE if the byte range exists and is a valid name
914 _dbus_validate_error_name (const DBusString *str,
918 /* Same restrictions as interface name at the moment */
919 return _dbus_validate_interface (str, start, len);
923 * Determine wether the given character is valid as the first character
926 #define VALID_INITIAL_BUS_NAME_CHARACTER(c) \
927 ( ((c) >= 'A' && (c) <= 'Z') || \
928 ((c) >= 'a' && (c) <= 'z') || \
929 ((c) == '_') || ((c) == '-'))
932 * Determine wether the given character is valid as a second or later
933 * character in a bus name
935 #define VALID_BUS_NAME_CHARACTER(c) \
936 ( ((c) >= '0' && (c) <= '9') || \
937 ((c) >= 'A' && (c) <= 'Z') || \
938 ((c) >= 'a' && (c) <= 'z') || \
939 ((c) == '_') || ((c) == '-'))
942 * Checks that the given range of the string is a valid bus name in
943 * the D-Bus protocol. This includes a length restriction, etc., see
946 * @todo this is inconsistent with most of DBusString in that
947 * it allows a start,len range that extends past the string end.
949 * @param str the string
950 * @param start first byte index to check
951 * @param len number of bytes to check
952 * @returns #TRUE if the byte range exists and is a valid name
955 _dbus_validate_bus_name (const DBusString *str,
959 const unsigned char *s;
960 const unsigned char *end;
961 const unsigned char *iface;
962 const unsigned char *last_dot;
964 _dbus_assert (start >= 0);
965 _dbus_assert (len >= 0);
966 _dbus_assert (start <= _dbus_string_get_length (str));
968 if (len > _dbus_string_get_length (str) - start)
971 if (len > DBUS_MAXIMUM_NAME_LENGTH)
978 iface = _dbus_string_get_const_data (str) + start;
982 /* check special cases of first char so it doesn't have to be done
983 * in the loop. Note we know len > 0
993 if (_DBUS_UNLIKELY ((s + 1) == end))
995 if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*(s + 1))))
997 ++s; /* we just validated the next char, so skip two */
999 else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
1009 else if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
1011 else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*s)))
1020 if (_DBUS_UNLIKELY ((s + 1) == end))
1022 else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*(s + 1))))
1025 ++s; /* we just validated the next char, so skip two */
1027 else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
1035 if (_DBUS_UNLIKELY (last_dot == NULL))
1042 * Checks that the given range of the string is a valid message type
1043 * signature in the D-Bus protocol.
1045 * @todo this is inconsistent with most of DBusString in that
1046 * it allows a start,len range that extends past the string end.
1048 * @param str the string
1049 * @param start first byte index to check
1050 * @param len number of bytes to check
1051 * @returns #TRUE if the byte range exists and is a valid signature
1054 _dbus_validate_signature (const DBusString *str,
1058 _dbus_assert (start >= 0);
1059 _dbus_assert (start <= _dbus_string_get_length (str));
1060 _dbus_assert (len >= 0);
1062 if (len > _dbus_string_get_length (str) - start)
1065 return _dbus_validate_signature_with_reason (str, start, len) == DBUS_VALID;
1068 /** define _dbus_check_is_valid_path() */
1069 DEFINE_DBUS_NAME_CHECK(path)
1070 /** define _dbus_check_is_valid_interface() */
1071 DEFINE_DBUS_NAME_CHECK(interface)
1072 /** define _dbus_check_is_valid_member() */
1073 DEFINE_DBUS_NAME_CHECK(member)
1074 /** define _dbus_check_is_valid_error_name() */
1075 DEFINE_DBUS_NAME_CHECK(error_name)
1076 /** define _dbus_check_is_valid_bus_name() */
1077 DEFINE_DBUS_NAME_CHECK(bus_name)
1078 /** define _dbus_check_is_valid_signature() */
1079 DEFINE_DBUS_NAME_CHECK(signature)
1083 /* tests in dbus-marshal-validate-util.c */