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)
251 if (!(_dbus_type_is_valid (*p) && dbus_type_is_basic (*p)))
253 result = DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE;
265 result = DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE;
269 if (struct_depth > 0)
271 result = DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED;
275 if (dict_entry_depth > 0)
277 result = DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED;
281 _dbus_assert (last != DBUS_TYPE_ARRAY);
282 _dbus_assert (last != DBUS_STRUCT_BEGIN_CHAR);
283 _dbus_assert (last != DBUS_DICT_ENTRY_BEGIN_CHAR);
288 _dbus_list_clear (&element_count_stack);
293 validate_body_helper (DBusTypeReader *reader,
295 dbus_bool_t walk_reader_to_end,
296 const unsigned char *p,
297 const unsigned char *end,
298 const unsigned char **new_p)
302 while ((current_type = _dbus_type_reader_get_current_type (reader)) != DBUS_TYPE_INVALID)
304 const unsigned char *a;
308 _dbus_verbose (" validating value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
309 _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
313 /* Guarantee that p has one byte to look at */
315 return DBUS_INVALID_NOT_ENOUGH_DATA;
317 switch (current_type)
323 case DBUS_TYPE_BOOLEAN:
324 case DBUS_TYPE_INT16:
325 case DBUS_TYPE_UINT16:
326 case DBUS_TYPE_INT32:
327 case DBUS_TYPE_UINT32:
328 case DBUS_TYPE_INT64:
329 case DBUS_TYPE_UINT64:
330 case DBUS_TYPE_DOUBLE:
331 alignment = _dbus_type_get_alignment (current_type);
332 a = _DBUS_ALIGN_ADDRESS (p, alignment);
334 return DBUS_INVALID_NOT_ENOUGH_DATA;
338 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
342 if (current_type == DBUS_TYPE_BOOLEAN)
344 dbus_uint32_t v = _dbus_unpack_uint32 (byte_order,
346 if (!(v == 0 || v == 1))
347 return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE;
353 case DBUS_TYPE_ARRAY:
354 case DBUS_TYPE_STRING:
355 case DBUS_TYPE_OBJECT_PATH:
357 dbus_uint32_t claimed_len;
359 a = _DBUS_ALIGN_ADDRESS (p, 4);
361 return DBUS_INVALID_NOT_ENOUGH_DATA;
365 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
369 claimed_len = _dbus_unpack_uint32 (byte_order, p);
372 /* p may now be == end */
373 _dbus_assert (p <= end);
375 if (current_type == DBUS_TYPE_ARRAY)
377 int array_elem_type = _dbus_type_reader_get_element_type (reader);
379 if (!_dbus_type_is_valid (array_elem_type))
381 return DBUS_INVALID_UNKNOWN_TYPECODE;
384 alignment = _dbus_type_get_alignment (array_elem_type);
386 a = _DBUS_ALIGN_ADDRESS (p, alignment);
388 /* a may now be == end */
390 return DBUS_INVALID_NOT_ENOUGH_DATA;
395 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
400 if (claimed_len > (unsigned long) (end - p))
401 return DBUS_INVALID_LENGTH_OUT_OF_BOUNDS;
403 if (current_type == DBUS_TYPE_OBJECT_PATH)
406 _dbus_string_init_const_len (&str, p, claimed_len);
407 if (!_dbus_validate_path (&str, 0,
408 _dbus_string_get_length (&str)))
409 return DBUS_INVALID_BAD_PATH;
413 else if (current_type == DBUS_TYPE_STRING)
416 _dbus_string_init_const_len (&str, p, claimed_len);
417 if (!_dbus_string_validate_utf8 (&str, 0,
418 _dbus_string_get_length (&str)))
419 return DBUS_INVALID_BAD_UTF8_IN_STRING;
423 else if (current_type == DBUS_TYPE_ARRAY && claimed_len > 0)
426 DBusValidity validity;
427 const unsigned char *array_end;
430 if (claimed_len > DBUS_MAXIMUM_ARRAY_LENGTH)
431 return DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM;
433 /* Remember that the reader is types only, so we can't
434 * use it to iterate over elements. It stays the same
437 _dbus_type_reader_recurse (reader, &sub);
439 array_end = p + claimed_len;
441 array_elem_type = _dbus_type_reader_get_element_type (reader);
443 /* avoid recursive call to validate_body_helper if this is an array
444 * of fixed-size elements
446 if (dbus_type_is_fixed (array_elem_type))
448 /* bools need to be handled differently, because they can
449 * have an invalid value
451 if (array_elem_type == DBUS_TYPE_BOOLEAN)
454 alignment = _dbus_type_get_alignment (array_elem_type);
456 while (p < array_end)
458 v = _dbus_unpack_uint32 (byte_order, p);
460 if (!(v == 0 || v == 1))
461 return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE;
475 while (p < array_end)
477 validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
478 if (validity != DBUS_VALID)
484 return DBUS_INVALID_ARRAY_LENGTH_INCORRECT;
487 /* check nul termination */
488 if (current_type != DBUS_TYPE_ARRAY)
491 return DBUS_INVALID_NOT_ENOUGH_DATA;
494 return DBUS_INVALID_STRING_MISSING_NUL;
500 case DBUS_TYPE_SIGNATURE:
502 dbus_uint32_t claimed_len;
504 DBusValidity validity;
509 /* 1 is for nul termination */
510 if (claimed_len + 1 > (unsigned long) (end - p))
511 return DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
513 _dbus_string_init_const_len (&str, p, claimed_len);
515 _dbus_validate_signature_with_reason (&str, 0,
516 _dbus_string_get_length (&str));
518 if (validity != DBUS_VALID)
523 _dbus_assert (p < end);
524 if (*p != DBUS_TYPE_INVALID)
525 return DBUS_INVALID_SIGNATURE_MISSING_NUL;
529 _dbus_verbose ("p = %p end = %p claimed_len %u\n", p, end, claimed_len);
533 case DBUS_TYPE_VARIANT:
535 /* 1 byte sig len, sig typecodes, align to
536 * contained-type-boundary, values.
539 /* In addition to normal signature validation, we need to be sure
540 * the signature contains only a single (possibly container) type.
542 dbus_uint32_t claimed_len;
545 DBusValidity validity;
546 int contained_alignment;
554 if (claimed_len + 1 > (unsigned long) (end - p))
555 return DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
557 _dbus_string_init_const_len (&sig, p, claimed_len);
558 reason = _dbus_validate_signature_with_reason (&sig, 0,
559 _dbus_string_get_length (&sig));
560 if (!(reason == DBUS_VALID))
562 if (reason == DBUS_VALIDITY_UNKNOWN_OOM_ERROR)
565 return DBUS_INVALID_VARIANT_SIGNATURE_BAD;
570 if (*p != DBUS_TYPE_INVALID)
571 return DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL;
574 contained_type = _dbus_first_type_in_signature (&sig, 0);
575 if (contained_type == DBUS_TYPE_INVALID)
576 return DBUS_INVALID_VARIANT_SIGNATURE_EMPTY;
578 contained_alignment = _dbus_type_get_alignment (contained_type);
580 a = _DBUS_ALIGN_ADDRESS (p, contained_alignment);
582 return DBUS_INVALID_NOT_ENOUGH_DATA;
586 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
590 _dbus_type_reader_init_types_only (&sub, &sig, 0);
592 _dbus_assert (_dbus_type_reader_get_current_type (&sub) != DBUS_TYPE_INVALID);
594 validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
595 if (validity != DBUS_VALID)
598 if (_dbus_type_reader_next (&sub))
599 return DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES;
601 _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_INVALID);
605 case DBUS_TYPE_DICT_ENTRY:
606 case DBUS_TYPE_STRUCT:
609 DBusValidity validity;
611 a = _DBUS_ALIGN_ADDRESS (p, 8);
613 return DBUS_INVALID_NOT_ENOUGH_DATA;
617 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
621 _dbus_type_reader_recurse (reader, &sub);
623 validity = validate_body_helper (&sub, byte_order, TRUE, p, end, &p);
624 if (validity != DBUS_VALID)
630 _dbus_assert_not_reached ("invalid typecode in supposedly-validated signature");
635 _dbus_verbose (" validated value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
636 _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
642 _dbus_verbose ("not enough data!!! p = %p end = %p end-p = %d\n",
643 p, end, (int) (end - p));
644 return DBUS_INVALID_NOT_ENOUGH_DATA;
647 if (walk_reader_to_end)
648 _dbus_type_reader_next (reader);
660 * Verifies that the range of value_str from value_pos to value_end is
661 * a legitimate value of type expected_signature. If this function
662 * returns #TRUE, it will be safe to iterate over the values with
663 * #DBusTypeReader. The signature is assumed to be already valid.
665 * If bytes_remaining is not #NULL, then leftover bytes will be stored
666 * there and #DBUS_VALID returned. If it is #NULL, then
667 * #DBUS_INVALID_TOO_MUCH_DATA will be returned if bytes are left
670 * @param expected_signature the expected types in the value_str
671 * @param expected_signature_start where in expected_signature is the signature
672 * @param byte_order the byte order
673 * @param bytes_remaining place to store leftover bytes
674 * @param value_str the string containing the body
675 * @param value_pos where the values start
676 * @param len length of values after value_pos
677 * @returns #DBUS_VALID if valid, reason why invalid otherwise
680 _dbus_validate_body_with_reason (const DBusString *expected_signature,
681 int expected_signature_start,
683 int *bytes_remaining,
684 const DBusString *value_str,
688 DBusTypeReader reader;
689 const unsigned char *p;
690 const unsigned char *end;
691 DBusValidity validity;
693 _dbus_assert (len >= 0);
694 _dbus_assert (value_pos >= 0);
695 _dbus_assert (value_pos <= _dbus_string_get_length (value_str) - len);
697 _dbus_verbose ("validating body from pos %d len %d sig '%s'\n",
698 value_pos, len, _dbus_string_get_const_data_len (expected_signature,
699 expected_signature_start,
702 _dbus_type_reader_init_types_only (&reader,
703 expected_signature, expected_signature_start);
705 p = _dbus_string_get_const_data_len (value_str, value_pos, len);
708 validity = validate_body_helper (&reader, byte_order, TRUE, p, end, &p);
709 if (validity != DBUS_VALID)
714 *bytes_remaining = end - p;
718 return DBUS_INVALID_TOO_MUCH_DATA;
721 _dbus_assert (p == end);
727 * Determine wether the given character is valid as the first character
730 #define VALID_INITIAL_NAME_CHARACTER(c) \
731 ( ((c) >= 'A' && (c) <= 'Z') || \
732 ((c) >= 'a' && (c) <= 'z') || \
736 * Determine wether the given character is valid as a second or later
737 * character in a name
739 #define VALID_NAME_CHARACTER(c) \
740 ( ((c) >= '0' && (c) <= '9') || \
741 ((c) >= 'A' && (c) <= 'Z') || \
742 ((c) >= 'a' && (c) <= 'z') || \
746 * Checks that the given range of the string is a valid object path
747 * name in the D-Bus protocol. Part of the validation ensures that
748 * the object path contains only ASCII.
750 * @todo this is inconsistent with most of DBusString in that
751 * it allows a start,len range that extends past the string end.
753 * @todo change spec to disallow more things, such as spaces in the
756 * @param str the string
757 * @param start first byte index to check
758 * @param len number of bytes to check
759 * @returns #TRUE if the byte range exists and is a valid name
762 _dbus_validate_path (const DBusString *str,
766 const unsigned char *s;
767 const unsigned char *end;
768 const unsigned char *last_slash;
770 _dbus_assert (start >= 0);
771 _dbus_assert (len >= 0);
772 _dbus_assert (start <= _dbus_string_get_length (str));
774 if (len > _dbus_string_get_length (str) - start)
780 s = _dbus_string_get_const_data (str) + start;
792 if ((s - last_slash) < 2)
793 return FALSE; /* no empty path components allowed */
799 if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
806 if ((end - last_slash) < 2 &&
808 return FALSE; /* trailing slash not allowed unless the string is "/" */
814 * Checks that the given range of the string is a valid interface name
815 * in the D-Bus protocol. This includes a length restriction and an
816 * ASCII subset, see the specification.
818 * @todo this is inconsistent with most of DBusString in that
819 * it allows a start,len range that extends past the string end.
821 * @param str the string
822 * @param start first byte index to check
823 * @param len number of bytes to check
824 * @returns #TRUE if the byte range exists and is a valid name
827 _dbus_validate_interface (const DBusString *str,
831 const unsigned char *s;
832 const unsigned char *end;
833 const unsigned char *iface;
834 const unsigned char *last_dot;
836 _dbus_assert (start >= 0);
837 _dbus_assert (len >= 0);
838 _dbus_assert (start <= _dbus_string_get_length (str));
840 if (len > _dbus_string_get_length (str) - start)
843 if (len > DBUS_MAXIMUM_NAME_LENGTH)
850 iface = _dbus_string_get_const_data (str) + start;
854 /* check special cases of first char so it doesn't have to be done
855 * in the loop. Note we know len > 0
857 if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
859 else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
868 if (_DBUS_UNLIKELY ((s + 1) == end))
870 else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*(s + 1))))
873 ++s; /* we just validated the next char, so skip two */
875 else if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
883 if (_DBUS_UNLIKELY (last_dot == NULL))
890 * Checks that the given range of the string is a valid member name
891 * in the D-Bus protocol. This includes a length restriction, etc.,
892 * see the specification.
894 * @todo this is inconsistent with most of DBusString in that
895 * it allows a start,len range that extends past the string end.
897 * @param str the string
898 * @param start first byte index to check
899 * @param len number of bytes to check
900 * @returns #TRUE if the byte range exists and is a valid name
903 _dbus_validate_member (const DBusString *str,
907 const unsigned char *s;
908 const unsigned char *end;
909 const unsigned char *member;
911 _dbus_assert (start >= 0);
912 _dbus_assert (len >= 0);
913 _dbus_assert (start <= _dbus_string_get_length (str));
915 if (len > _dbus_string_get_length (str) - start)
918 if (len > DBUS_MAXIMUM_NAME_LENGTH)
924 member = _dbus_string_get_const_data (str) + start;
928 /* check special cases of first char so it doesn't have to be done
929 * in the loop. Note we know len > 0
932 if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
939 if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
951 * Checks that the given range of the string is a valid error name
952 * in the D-Bus protocol. This includes a length restriction, etc.,
953 * see the specification.
955 * @todo this is inconsistent with most of DBusString in that
956 * it allows a start,len range that extends past the string end.
958 * @param str the string
959 * @param start first byte index to check
960 * @param len number of bytes to check
961 * @returns #TRUE if the byte range exists and is a valid name
964 _dbus_validate_error_name (const DBusString *str,
968 /* Same restrictions as interface name at the moment */
969 return _dbus_validate_interface (str, start, len);
973 * Determine wether the given character is valid as the first character
976 #define VALID_INITIAL_BUS_NAME_CHARACTER(c) \
977 ( ((c) >= 'A' && (c) <= 'Z') || \
978 ((c) >= 'a' && (c) <= 'z') || \
979 ((c) == '_') || ((c) == '-'))
982 * Determine wether the given character is valid as a second or later
983 * character in a bus name
985 #define VALID_BUS_NAME_CHARACTER(c) \
986 ( ((c) >= '0' && (c) <= '9') || \
987 ((c) >= 'A' && (c) <= 'Z') || \
988 ((c) >= 'a' && (c) <= 'z') || \
989 ((c) == '_') || ((c) == '-'))
992 * Checks that the given range of the string is a valid bus name in
993 * the D-Bus protocol. This includes a length restriction, etc., see
996 * @todo this is inconsistent with most of DBusString in that
997 * it allows a start,len range that extends past the string end.
999 * @param str the string
1000 * @param start first byte index to check
1001 * @param len number of bytes to check
1002 * @returns #TRUE if the byte range exists and is a valid name
1005 _dbus_validate_bus_name (const DBusString *str,
1009 const unsigned char *s;
1010 const unsigned char *end;
1011 const unsigned char *iface;
1012 const unsigned char *last_dot;
1014 _dbus_assert (start >= 0);
1015 _dbus_assert (len >= 0);
1016 _dbus_assert (start <= _dbus_string_get_length (str));
1018 if (len > _dbus_string_get_length (str) - start)
1021 if (len > DBUS_MAXIMUM_NAME_LENGTH)
1028 iface = _dbus_string_get_const_data (str) + start;
1032 /* check special cases of first char so it doesn't have to be done
1033 * in the loop. Note we know len > 0
1043 if (_DBUS_UNLIKELY ((s + 1) == end))
1045 if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*(s + 1))))
1047 ++s; /* we just validated the next char, so skip two */
1049 else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
1059 else if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
1061 else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*s)))
1070 if (_DBUS_UNLIKELY ((s + 1) == end))
1072 else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*(s + 1))))
1075 ++s; /* we just validated the next char, so skip two */
1077 else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
1085 if (_DBUS_UNLIKELY (last_dot == NULL))
1092 * Checks that the given range of the string is a valid message type
1093 * signature in the D-Bus protocol.
1095 * @todo this is inconsistent with most of DBusString in that
1096 * it allows a start,len range that extends past the string end.
1098 * @param str the string
1099 * @param start first byte index to check
1100 * @param len number of bytes to check
1101 * @returns #TRUE if the byte range exists and is a valid signature
1104 _dbus_validate_signature (const DBusString *str,
1108 _dbus_assert (start >= 0);
1109 _dbus_assert (start <= _dbus_string_get_length (str));
1110 _dbus_assert (len >= 0);
1112 if (len > _dbus_string_get_length (str) - start)
1115 return _dbus_validate_signature_with_reason (str, start, len) == DBUS_VALID;
1118 /** define _dbus_check_is_valid_path() */
1119 DEFINE_DBUS_NAME_CHECK(path)
1120 /** define _dbus_check_is_valid_interface() */
1121 DEFINE_DBUS_NAME_CHECK(interface)
1122 /** define _dbus_check_is_valid_member() */
1123 DEFINE_DBUS_NAME_CHECK(member)
1124 /** define _dbus_check_is_valid_error_name() */
1125 DEFINE_DBUS_NAME_CHECK(error_name)
1126 /** define _dbus_check_is_valid_bus_name() */
1127 DEFINE_DBUS_NAME_CHECK(bus_name)
1128 /** define _dbus_check_is_valid_signature() */
1129 DEFINE_DBUS_NAME_CHECK(signature)
1133 /* tests in dbus-marshal-validate-util.c */