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_basic (*p))
252 result = DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE;
263 result = DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE;
267 if (struct_depth > 0)
269 result = DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED;
273 if (dict_entry_depth > 0)
275 result = DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED;
279 _dbus_assert (last != DBUS_TYPE_ARRAY);
280 _dbus_assert (last != DBUS_STRUCT_BEGIN_CHAR);
281 _dbus_assert (last != DBUS_DICT_ENTRY_BEGIN_CHAR);
286 _dbus_list_clear (&element_count_stack);
291 validate_body_helper (DBusTypeReader *reader,
293 dbus_bool_t walk_reader_to_end,
294 const unsigned char *p,
295 const unsigned char *end,
296 const unsigned char **new_p)
300 while ((current_type = _dbus_type_reader_get_current_type (reader)) != DBUS_TYPE_INVALID)
302 const unsigned char *a;
306 _dbus_verbose (" validating value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
307 _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
311 /* Guarantee that p has one byte to look at */
313 return DBUS_INVALID_NOT_ENOUGH_DATA;
315 switch (current_type)
321 case DBUS_TYPE_BOOLEAN:
322 case DBUS_TYPE_INT16:
323 case DBUS_TYPE_UINT16:
324 case DBUS_TYPE_INT32:
325 case DBUS_TYPE_UINT32:
326 case DBUS_TYPE_INT64:
327 case DBUS_TYPE_UINT64:
328 case DBUS_TYPE_DOUBLE:
329 alignment = _dbus_type_get_alignment (current_type);
330 a = _DBUS_ALIGN_ADDRESS (p, alignment);
332 return DBUS_INVALID_NOT_ENOUGH_DATA;
336 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
340 if (current_type == DBUS_TYPE_BOOLEAN)
342 dbus_uint32_t v = _dbus_unpack_uint32 (byte_order,
344 if (!(v == 0 || v == 1))
345 return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE;
351 case DBUS_TYPE_ARRAY:
352 case DBUS_TYPE_STRING:
353 case DBUS_TYPE_OBJECT_PATH:
355 dbus_uint32_t claimed_len;
357 a = _DBUS_ALIGN_ADDRESS (p, 4);
359 return DBUS_INVALID_NOT_ENOUGH_DATA;
363 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
367 claimed_len = _dbus_unpack_uint32 (byte_order, p);
370 /* p may now be == end */
371 _dbus_assert (p <= end);
373 if (current_type == DBUS_TYPE_ARRAY)
375 int array_elem_type = _dbus_type_reader_get_element_type (reader);
376 alignment = _dbus_type_get_alignment (array_elem_type);
377 p = _DBUS_ALIGN_ADDRESS (p, alignment);
380 if (claimed_len > (unsigned long) (end - p))
381 return DBUS_INVALID_LENGTH_OUT_OF_BOUNDS;
383 if (current_type == DBUS_TYPE_OBJECT_PATH)
386 _dbus_string_init_const_len (&str, p, claimed_len);
387 if (!_dbus_validate_path (&str, 0,
388 _dbus_string_get_length (&str)))
389 return DBUS_INVALID_BAD_PATH;
393 else if (current_type == DBUS_TYPE_STRING)
396 _dbus_string_init_const_len (&str, p, claimed_len);
397 if (!_dbus_string_validate_utf8 (&str, 0,
398 _dbus_string_get_length (&str)))
399 return DBUS_INVALID_BAD_UTF8_IN_STRING;
403 else if (current_type == DBUS_TYPE_ARRAY && claimed_len > 0)
406 DBusValidity validity;
407 const unsigned char *array_end;
409 if (claimed_len > DBUS_MAXIMUM_ARRAY_LENGTH)
410 return DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM;
412 /* Remember that the reader is types only, so we can't
413 * use it to iterate over elements. It stays the same
416 _dbus_type_reader_recurse (reader, &sub);
418 array_end = p + claimed_len;
420 while (p < array_end)
422 /* FIXME we are calling a function per array element! very bad
423 * need if (dbus_type_is_fixed(elem_type)) here to just skip
424 * big blocks of ints/bytes/etc.
427 validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
428 if (validity != DBUS_VALID)
433 return DBUS_INVALID_ARRAY_LENGTH_INCORRECT;
436 /* check nul termination */
437 if (current_type != DBUS_TYPE_ARRAY)
440 return DBUS_INVALID_NOT_ENOUGH_DATA;
443 return DBUS_INVALID_STRING_MISSING_NUL;
449 case DBUS_TYPE_SIGNATURE:
451 dbus_uint32_t claimed_len;
453 DBusValidity validity;
458 /* 1 is for nul termination */
459 if (claimed_len + 1 > (unsigned long) (end - p))
460 return DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
462 _dbus_string_init_const_len (&str, p, claimed_len);
464 _dbus_validate_signature_with_reason (&str, 0,
465 _dbus_string_get_length (&str));
467 if (validity != DBUS_VALID)
472 _dbus_assert (p < end);
473 if (*p != DBUS_TYPE_INVALID)
474 return DBUS_INVALID_SIGNATURE_MISSING_NUL;
478 _dbus_verbose ("p = %p end = %p claimed_len %u\n", p, end, claimed_len);
482 case DBUS_TYPE_VARIANT:
484 /* 1 byte sig len, sig typecodes, align to
485 * contained-type-boundary, values.
488 /* In addition to normal signature validation, we need to be sure
489 * the signature contains only a single (possibly container) type.
491 dbus_uint32_t claimed_len;
494 DBusValidity validity;
495 int contained_alignment;
503 if (claimed_len + 1 > (unsigned long) (end - p))
504 return DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
506 _dbus_string_init_const_len (&sig, p, claimed_len);
507 reason = _dbus_validate_signature_with_reason (&sig, 0,
508 _dbus_string_get_length (&sig));
509 if (!(reason == DBUS_VALID))
511 if (reason == DBUS_VALIDITY_UNKNOWN_OOM_ERROR)
514 return DBUS_INVALID_VARIANT_SIGNATURE_BAD;
519 if (*p != DBUS_TYPE_INVALID)
520 return DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL;
523 contained_type = _dbus_first_type_in_signature (&sig, 0);
524 if (contained_type == DBUS_TYPE_INVALID)
525 return DBUS_INVALID_VARIANT_SIGNATURE_EMPTY;
527 contained_alignment = _dbus_type_get_alignment (contained_type);
529 a = _DBUS_ALIGN_ADDRESS (p, contained_alignment);
531 return DBUS_INVALID_NOT_ENOUGH_DATA;
535 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
539 _dbus_type_reader_init_types_only (&sub, &sig, 0);
541 _dbus_assert (_dbus_type_reader_get_current_type (&sub) != DBUS_TYPE_INVALID);
543 validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
544 if (validity != DBUS_VALID)
547 if (_dbus_type_reader_next (&sub))
548 return DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES;
550 _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_INVALID);
554 case DBUS_TYPE_DICT_ENTRY:
555 case DBUS_TYPE_STRUCT:
558 DBusValidity validity;
560 a = _DBUS_ALIGN_ADDRESS (p, 8);
562 return DBUS_INVALID_NOT_ENOUGH_DATA;
566 return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
570 _dbus_type_reader_recurse (reader, &sub);
572 validity = validate_body_helper (&sub, byte_order, TRUE, p, end, &p);
573 if (validity != DBUS_VALID)
579 _dbus_assert_not_reached ("invalid typecode in supposedly-validated signature");
584 _dbus_verbose (" validated value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
585 _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
591 _dbus_verbose ("not enough data!!! p = %p end = %p end-p = %d\n",
592 p, end, (int) (end - p));
593 return DBUS_INVALID_NOT_ENOUGH_DATA;
596 if (walk_reader_to_end)
597 _dbus_type_reader_next (reader);
609 * Verifies that the range of value_str from value_pos to value_end is
610 * a legitimate value of type expected_signature. If this function
611 * returns #TRUE, it will be safe to iterate over the values with
612 * #DBusTypeReader. The signature is assumed to be already valid.
614 * If bytes_remaining is not #NULL, then leftover bytes will be stored
615 * there and #DBUS_VALID returned. If it is #NULL, then
616 * #DBUS_INVALID_TOO_MUCH_DATA will be returned if bytes are left
619 * @param expected_signature the expected types in the value_str
620 * @param expected_signature_start where in expected_signature is the signature
621 * @param byte_order the byte order
622 * @param bytes_remaining place to store leftover bytes
623 * @param value_str the string containing the body
624 * @param value_pos where the values start
625 * @param len length of values after value_pos
626 * @returns #DBUS_VALID if valid, reason why invalid otherwise
629 _dbus_validate_body_with_reason (const DBusString *expected_signature,
630 int expected_signature_start,
632 int *bytes_remaining,
633 const DBusString *value_str,
637 DBusTypeReader reader;
638 const unsigned char *p;
639 const unsigned char *end;
640 DBusValidity validity;
642 _dbus_assert (len >= 0);
643 _dbus_assert (value_pos >= 0);
644 _dbus_assert (value_pos <= _dbus_string_get_length (value_str) - len);
646 _dbus_verbose ("validating body from pos %d len %d sig '%s'\n",
647 value_pos, len, _dbus_string_get_const_data_len (expected_signature,
648 expected_signature_start,
651 _dbus_type_reader_init_types_only (&reader,
652 expected_signature, expected_signature_start);
654 p = _dbus_string_get_const_data_len (value_str, value_pos, len);
657 validity = validate_body_helper (&reader, byte_order, TRUE, p, end, &p);
658 if (validity != DBUS_VALID)
663 *bytes_remaining = end - p;
667 return DBUS_INVALID_TOO_MUCH_DATA;
670 _dbus_assert (p == end);
676 * Determine wether the given character is valid as the first character
679 #define VALID_INITIAL_NAME_CHARACTER(c) \
680 ( ((c) >= 'A' && (c) <= 'Z') || \
681 ((c) >= 'a' && (c) <= 'z') || \
685 * Determine wether the given character is valid as a second or later
686 * character in a name
688 #define VALID_NAME_CHARACTER(c) \
689 ( ((c) >= '0' && (c) <= '9') || \
690 ((c) >= 'A' && (c) <= 'Z') || \
691 ((c) >= 'a' && (c) <= 'z') || \
695 * Checks that the given range of the string is a valid object path
696 * name in the D-Bus protocol. Part of the validation ensures that
697 * the object path contains only ASCII.
699 * @todo this is inconsistent with most of DBusString in that
700 * it allows a start,len range that extends past the string end.
702 * @todo change spec to disallow more things, such as spaces in the
705 * @param str the string
706 * @param start first byte index to check
707 * @param len number of bytes to check
708 * @returns #TRUE if the byte range exists and is a valid name
711 _dbus_validate_path (const DBusString *str,
715 const unsigned char *s;
716 const unsigned char *end;
717 const unsigned char *last_slash;
719 _dbus_assert (start >= 0);
720 _dbus_assert (len >= 0);
721 _dbus_assert (start <= _dbus_string_get_length (str));
723 if (len > _dbus_string_get_length (str) - start)
729 s = _dbus_string_get_const_data (str) + start;
741 if ((s - last_slash) < 2)
742 return FALSE; /* no empty path components allowed */
748 if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
755 if ((end - last_slash) < 2 &&
757 return FALSE; /* trailing slash not allowed unless the string is "/" */
763 * Checks that the given range of the string is a valid interface name
764 * in the D-Bus protocol. This includes a length restriction and an
765 * ASCII subset, see the specification.
767 * @todo this is inconsistent with most of DBusString in that
768 * it allows a start,len range that extends past the string end.
770 * @param str the string
771 * @param start first byte index to check
772 * @param len number of bytes to check
773 * @returns #TRUE if the byte range exists and is a valid name
776 _dbus_validate_interface (const DBusString *str,
780 const unsigned char *s;
781 const unsigned char *end;
782 const unsigned char *iface;
783 const unsigned char *last_dot;
785 _dbus_assert (start >= 0);
786 _dbus_assert (len >= 0);
787 _dbus_assert (start <= _dbus_string_get_length (str));
789 if (len > _dbus_string_get_length (str) - start)
792 if (len > DBUS_MAXIMUM_NAME_LENGTH)
799 iface = _dbus_string_get_const_data (str) + start;
803 /* check special cases of first char so it doesn't have to be done
804 * in the loop. Note we know len > 0
806 if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
808 else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
817 if (_DBUS_UNLIKELY ((s + 1) == end))
819 else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*(s + 1))))
822 ++s; /* we just validated the next char, so skip two */
824 else if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
832 if (_DBUS_UNLIKELY (last_dot == NULL))
839 * Checks that the given range of the string is a valid member name
840 * in the D-Bus protocol. This includes a length restriction, etc.,
841 * see the specification.
843 * @todo this is inconsistent with most of DBusString in that
844 * it allows a start,len range that extends past the string end.
846 * @param str the string
847 * @param start first byte index to check
848 * @param len number of bytes to check
849 * @returns #TRUE if the byte range exists and is a valid name
852 _dbus_validate_member (const DBusString *str,
856 const unsigned char *s;
857 const unsigned char *end;
858 const unsigned char *member;
860 _dbus_assert (start >= 0);
861 _dbus_assert (len >= 0);
862 _dbus_assert (start <= _dbus_string_get_length (str));
864 if (len > _dbus_string_get_length (str) - start)
867 if (len > DBUS_MAXIMUM_NAME_LENGTH)
873 member = _dbus_string_get_const_data (str) + start;
877 /* check special cases of first char so it doesn't have to be done
878 * in the loop. Note we know len > 0
881 if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
888 if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
900 * Checks that the given range of the string is a valid error name
901 * in the D-Bus protocol. This includes a length restriction, etc.,
902 * see the specification.
904 * @todo this is inconsistent with most of DBusString in that
905 * it allows a start,len range that extends past the string end.
907 * @param str the string
908 * @param start first byte index to check
909 * @param len number of bytes to check
910 * @returns #TRUE if the byte range exists and is a valid name
913 _dbus_validate_error_name (const DBusString *str,
917 /* Same restrictions as interface name at the moment */
918 return _dbus_validate_interface (str, start, len);
922 * Determine wether the given character is valid as the first character
925 #define VALID_INITIAL_BUS_NAME_CHARACTER(c) \
926 ( ((c) >= 'A' && (c) <= 'Z') || \
927 ((c) >= 'a' && (c) <= 'z') || \
928 ((c) == '_') || ((c) == '-'))
931 * Determine wether the given character is valid as a second or later
932 * character in a bus name
934 #define VALID_BUS_NAME_CHARACTER(c) \
935 ( ((c) >= '0' && (c) <= '9') || \
936 ((c) >= 'A' && (c) <= 'Z') || \
937 ((c) >= 'a' && (c) <= 'z') || \
938 ((c) == '_') || ((c) == '-'))
941 * Checks that the given range of the string is a valid bus name in
942 * the D-Bus protocol. This includes a length restriction, etc., see
945 * @todo this is inconsistent with most of DBusString in that
946 * it allows a start,len range that extends past the string end.
948 * @param str the string
949 * @param start first byte index to check
950 * @param len number of bytes to check
951 * @returns #TRUE if the byte range exists and is a valid name
954 _dbus_validate_bus_name (const DBusString *str,
958 const unsigned char *s;
959 const unsigned char *end;
960 const unsigned char *iface;
961 const unsigned char *last_dot;
963 _dbus_assert (start >= 0);
964 _dbus_assert (len >= 0);
965 _dbus_assert (start <= _dbus_string_get_length (str));
967 if (len > _dbus_string_get_length (str) - start)
970 if (len > DBUS_MAXIMUM_NAME_LENGTH)
977 iface = _dbus_string_get_const_data (str) + start;
981 /* check special cases of first char so it doesn't have to be done
982 * in the loop. Note we know len > 0
992 if (_DBUS_UNLIKELY ((s + 1) == end))
994 if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*(s + 1))))
996 ++s; /* we just validated the next char, so skip two */
998 else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
1008 else if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
1010 else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*s)))
1019 if (_DBUS_UNLIKELY ((s + 1) == end))
1021 else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*(s + 1))))
1024 ++s; /* we just validated the next char, so skip two */
1026 else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
1034 if (_DBUS_UNLIKELY (last_dot == NULL))
1041 * Checks that the given range of the string is a valid message type
1042 * signature in the D-Bus protocol.
1044 * @todo this is inconsistent with most of DBusString in that
1045 * it allows a start,len range that extends past the string end.
1047 * @param str the string
1048 * @param start first byte index to check
1049 * @param len number of bytes to check
1050 * @returns #TRUE if the byte range exists and is a valid signature
1053 _dbus_validate_signature (const DBusString *str,
1057 _dbus_assert (start >= 0);
1058 _dbus_assert (start <= _dbus_string_get_length (str));
1059 _dbus_assert (len >= 0);
1061 if (len > _dbus_string_get_length (str) - start)
1064 return _dbus_validate_signature_with_reason (str, start, len) == DBUS_VALID;
1067 /** define _dbus_check_is_valid_path() */
1068 DEFINE_DBUS_NAME_CHECK(path)
1069 /** define _dbus_check_is_valid_interface() */
1070 DEFINE_DBUS_NAME_CHECK(interface)
1071 /** define _dbus_check_is_valid_member() */
1072 DEFINE_DBUS_NAME_CHECK(member)
1073 /** define _dbus_check_is_valid_error_name() */
1074 DEFINE_DBUS_NAME_CHECK(error_name)
1075 /** define _dbus_check_is_valid_bus_name() */
1076 DEFINE_DBUS_NAME_CHECK(bus_name)
1077 /** define _dbus_check_is_valid_signature() */
1078 DEFINE_DBUS_NAME_CHECK(signature)
1082 /* tests in dbus-marshal-validate-util.c */