Coverage report for dbus/dbus-marshal-validate.c.gcov
-: 0:Source:dbus-marshal-validate.c
-: 0:Graph:.libs/dbus-marshal-validate.gcno
-: 0:Data:.libs/dbus-marshal-validate.gcda
-: 0:Runs:11824
-: 0:Programs:5
-: 1:/* -*- mode: C; c-file-style: "gnu" -*- */
-: 2:/* dbus-marshal-validate.c Validation routines for marshaled data
-: 3: *
-: 4: * Copyright (C) 2005 Red Hat, Inc.
-: 5: *
-: 6: * Licensed under the Academic Free License version 2.1
-: 7: *
-: 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.
-: 12: *
-: 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.
-: 17: *
-: 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
-: 21: *
-: 22: */
-: 23:
-: 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"
-: 30:
-: 31:/**
-: 32: * @addtogroup DBusMarshal
-: 33: *
-: 34: * @{
-: 35: */
-: 36:
-: 37:/**
-: 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.
-: 43: *
-: 44: * @todo verify that dict entries have exactly two fields
-: 45: *
-: 46: * @todo require that dict entries are in an array
-: 47: *
-: 48: * @param type_str the string
-: 49: * @param type_pos where the typecodes start
-: 50: * @param len length of typecodes
-: 51: * @returns #DBUS_VALID if valid, reason why invalid otherwise
-: 52: */
-: 53:DBusValidity
-: 54:_dbus_validate_signature_with_reason (const DBusString *type_str,
-: 55: int type_pos,
-: 56: int len)
function _dbus_validate_signature_with_reason called 1083462 returned 100% blocks executed 93%
1083462: 57:{
-: 58: const unsigned char *p;
-: 59: const unsigned char *end;
-: 60: int last;
-: 61: int struct_depth;
-: 62: int array_depth;
-: 63: int dict_entry_depth;
-: 64: DBusValidity result;
-: 65:
-: 66: int element_count;
-: 67: DBusList *element_count_stack;
-: 68:
1083462: 69: result = DBUS_VALID;
1083462: 70: element_count_stack = NULL;
-: 71:
1083462: 72: if (!_dbus_list_append (&element_count_stack, _DBUS_INT_TO_POINTER (0)))
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
-: 73: {
4097: 74: result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
4097: 75: goto out;
-: 76: }
-: 77:
1079365: 78: _dbus_assert (type_str != NULL);
call 0 returned 100%
1079365: 79: _dbus_assert (type_pos < _DBUS_INT32_MAX - len);
call 0 returned 100%
1079365: 80: _dbus_assert (len >= 0);
call 0 returned 100%
1079365: 81: _dbus_assert (type_pos >= 0);
call 0 returned 100%
-: 82:
1079365: 83: if (len > DBUS_MAXIMUM_SIGNATURE_LENGTH)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
-: 84: {
#####: 85: result = DBUS_INVALID_SIGNATURE_TOO_LONG;
#####: 86: goto out;
-: 87: }
-: 88:
1079365: 89: p = _dbus_string_get_const_data_len (type_str, type_pos, 0);
call 0 returned 100%
-: 90:
1079365: 91: end = _dbus_string_get_const_data_len (type_str, type_pos + len, 0);
call 0 returned 100%
1079365: 92: struct_depth = 0;
1079365: 93: array_depth = 0;
1079365: 94: dict_entry_depth = 0;
1079365: 95: last = DBUS_TYPE_INVALID;
-: 96:
3425071: 97: while (p != end)
branch 0 taken 54%
branch 1 taken 46% (fallthrough)
-: 98: {
1274099: 99: switch (*p)
branch 0 taken 91%
branch 1 taken 3%
branch 2 taken 2%
branch 3 taken 1%
branch 4 taken 1%
branch 5 taken 1%
branch 6 taken 1%
-: 100: {
-: 101: case DBUS_TYPE_BYTE:
-: 102: case DBUS_TYPE_BOOLEAN:
-: 103: case DBUS_TYPE_INT16:
-: 104: case DBUS_TYPE_UINT16:
-: 105: case DBUS_TYPE_INT32:
-: 106: case DBUS_TYPE_UINT32:
-: 107: case DBUS_TYPE_INT64:
-: 108: case DBUS_TYPE_UINT64:
-: 109: case DBUS_TYPE_DOUBLE:
-: 110: case DBUS_TYPE_STRING:
-: 111: case DBUS_TYPE_OBJECT_PATH:
-: 112: case DBUS_TYPE_SIGNATURE:
-: 113: case DBUS_TYPE_VARIANT:
1165071: 114: break;
-: 115:
-: 116: case DBUS_TYPE_ARRAY:
42116: 117: array_depth += 1;
42116: 118: if (array_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 119: {
3: 120: result = DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION;
3: 121: goto out;
-: 122: }
42113: 123: break;
-: 124:
-: 125: case DBUS_STRUCT_BEGIN_CHAR:
19684: 126: struct_depth += 1;
-: 127:
19684: 128: if (struct_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 129: {
4: 130: result = DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION;
4: 131: goto out;
-: 132: }
-: 133:
19680: 134: if (!_dbus_list_append (&element_count_stack,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 135: _DBUS_INT_TO_POINTER (0)))
-: 136: {
#####: 137: result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
#####: 138: goto out;
-: 139: }
-: 140:
19680: 141: break;
-: 142:
-: 143: case DBUS_STRUCT_END_CHAR:
18482: 144: if (struct_depth == 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 145: {
5: 146: result = DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED;
5: 147: goto out;
-: 148: }
-: 149:
18477: 150: if (last == DBUS_STRUCT_BEGIN_CHAR)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 151: {
6: 152: result = DBUS_INVALID_STRUCT_HAS_NO_FIELDS;
6: 153: goto out;
-: 154: }
-: 155:
18471: 156: _dbus_list_pop_last (&element_count_stack);
call 0 returned 100%
-: 157:
18471: 158: struct_depth -= 1;
18471: 159: break;
-: 160:
-: 161: case DBUS_DICT_ENTRY_BEGIN_CHAR:
11304: 162: if (last != DBUS_TYPE_ARRAY)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 163: {
15: 164: result = DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY;
15: 165: goto out;
-: 166: }
-: 167:
11289: 168: dict_entry_depth += 1;
-: 169:
11289: 170: if (dict_entry_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 171: {
3: 172: result = DBUS_INVALID_EXCEEDED_MAXIMUM_DICT_ENTRY_RECURSION;
3: 173: goto out;
-: 174: }
-: 175:
11286: 176: if (!_dbus_list_append (&element_count_stack,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 177: _DBUS_INT_TO_POINTER (0)))
-: 178: {
#####: 179: result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
#####: 180: goto out;
-: 181: }
-: 182:
11286: 183: break;
-: 184:
-: 185: case DBUS_DICT_ENTRY_END_CHAR:
10547: 186: if (dict_entry_depth == 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 187: {
4: 188: result = DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED;
4: 189: goto out;
-: 190: }
-: 191:
10543: 192: dict_entry_depth -= 1;
-: 193:
10543: 194: element_count =
call 0 returned 100%
-: 195: _DBUS_POINTER_TO_INT (_dbus_list_pop_last (&element_count_stack));
-: 196:
10543: 197: if (element_count != 2)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 198: {
3: 199: if (element_count == 0)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
3: 200: result = DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS;
#####: 201: else if (element_count == 1)
branch 0 never executed
branch 1 never executed
#####: 202: result = DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD;
-: 203: else
#####: 204: result = DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS;
-: 205:
3: 206: goto out;
-: 207: }
10540: 208: break;
-: 209:
-: 210: case DBUS_TYPE_STRUCT: /* doesn't appear in signatures */
-: 211: case DBUS_TYPE_DICT_ENTRY: /* ditto */
-: 212: default:
6895: 213: result = DBUS_INVALID_UNKNOWN_TYPECODE;
6895: 214: goto out;
-: 215: }
-: 216:
1267161: 217: if (*p != DBUS_TYPE_ARRAY &&
branch 0 taken 97% (fallthrough)
branch 1 taken 3%
branch 2 taken 99% (fallthrough)
branch 3 taken 1%
branch 4 taken 98% (fallthrough)
branch 5 taken 2%
-: 218: *p != DBUS_DICT_ENTRY_BEGIN_CHAR &&
-: 219: *p != DBUS_STRUCT_BEGIN_CHAR)
-: 220: {
1194082: 221: element_count =
call 0 returned 100%
-: 222: _DBUS_POINTER_TO_INT (_dbus_list_pop_last (&element_count_stack));
-: 223:
1194082: 224: ++element_count;
-: 225:
1194082: 226: if (!_dbus_list_append (&element_count_stack,
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
-: 227: _DBUS_INT_TO_POINTER (element_count)))
-: 228: {
812: 229: result = DBUS_VALIDITY_UNKNOWN_OOM_ERROR;
812: 230: goto out;
-: 231: }
-: 232: }
-: 233:
1266349: 234: if (array_depth > 0)
branch 0 taken 7% (fallthrough)
branch 1 taken 93%
-: 235: {
125721: 236: if (*p == DBUS_TYPE_ARRAY && p != end)
branch 0 taken 50% (fallthrough)
branch 1 taken 50%
branch 2 taken 100% (fallthrough)
branch 3 taken 0%
-: 237: {
-: 238: const char *p1;
42113: 239: p1 = p + 1;
42113: 240: if (*p1 == DBUS_STRUCT_END_CHAR ||
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
branch 2 taken 1% (fallthrough)
branch 3 taken 99%
-: 241: *p1 == DBUS_DICT_ENTRY_END_CHAR)
-: 242: {
7: 243: result = DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE;
7: 244: goto out;
-: 245: }
-: 246: }
-: 247: else
-: 248: {
41502: 249: array_depth = 0;
-: 250: }
-: 251: }
-: 252:
1266342: 253: if (last == DBUS_DICT_ENTRY_BEGIN_CHAR &&
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
call 2 returned 100%
branch 3 taken 1% (fallthrough)
branch 4 taken 99%
-: 254: !dbus_type_is_basic (*p))
-: 255: {
1: 256: result = DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE;
1: 257: goto out;
-: 258: }
-: 259:
1266341: 260: last = *p;
1266341: 261: ++p;
-: 262: }
-: 263:
-: 264:
1071607: 265: if (array_depth > 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 266: {
175: 267: result = DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE;
175: 268: goto out;
-: 269: }
-: 270:
1071432: 271: if (struct_depth > 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 272: {
277: 273: result = DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED;
277: 274: goto out;
-: 275: }
-: 276:
1071155: 277: if (dict_entry_depth > 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 278: {
144: 279: result = DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED;
144: 280: goto out;
-: 281: }
-: 282:
1071011: 283: _dbus_assert (last != DBUS_TYPE_ARRAY);
call 0 returned 100%
1071011: 284: _dbus_assert (last != DBUS_STRUCT_BEGIN_CHAR);
call 0 returned 100%
1071011: 285: _dbus_assert (last != DBUS_DICT_ENTRY_BEGIN_CHAR);
call 0 returned 100%
-: 286:
1071011: 287: result = DBUS_VALID;
-: 288:
1083462: 289:out:
1083462: 290: _dbus_list_clear (&element_count_stack);
call 0 returned 100%
1083462: 291: return result;
-: 292:}
-: 293:
-: 294:static DBusValidity
-: 295:validate_body_helper (DBusTypeReader *reader,
-: 296: int byte_order,
-: 297: dbus_bool_t walk_reader_to_end,
-: 298: const unsigned char *p,
-: 299: const unsigned char *end,
-: 300: const unsigned char **new_p)
function validate_body_helper called 3240820 returned 100% blocks executed 98%
3240820: 301:{
-: 302: int current_type;
-: 303:
9947416: 304: while ((current_type = _dbus_type_reader_get_current_type (reader)) != DBUS_TYPE_INVALID)
call 0 returned 100%
branch 1 taken 83%
branch 2 taken 17% (fallthrough)
-: 305: {
-: 306: const unsigned char *a;
-: 307: int alignment;
-: 308:
-: 309:#if 0
-: 310: _dbus_verbose (" validating value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
-: 311: _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
-: 312: (int) (end - p));
-: 313:#endif
-: 314:
-: 315: /* Guarantee that p has one byte to look at */
5561638: 316: if (p == end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
741: 317: return DBUS_INVALID_NOT_ENOUGH_DATA;
-: 318:
5560897: 319: switch (current_type)
branch 0 taken 33%
branch 1 taken 10%
branch 2 taken 20%
branch 3 taken 2%
branch 4 taken 17%
branch 5 taken 18%
branch 6 taken 0%
-: 320: {
-: 321: case DBUS_TYPE_BYTE:
1825839: 322: ++p;
1825839: 323: break;
-: 324:
-: 325: case DBUS_TYPE_BOOLEAN:
-: 326: case DBUS_TYPE_INT16:
-: 327: case DBUS_TYPE_UINT16:
-: 328: case DBUS_TYPE_INT32:
-: 329: case DBUS_TYPE_UINT32:
-: 330: case DBUS_TYPE_INT64:
-: 331: case DBUS_TYPE_UINT64:
-: 332: case DBUS_TYPE_DOUBLE:
563105: 333: alignment = _dbus_type_get_alignment (current_type);
call 0 returned 100%
563105: 334: a = _DBUS_ALIGN_ADDRESS (p, alignment);
563105: 335: if (a >= end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
33: 336: return DBUS_INVALID_NOT_ENOUGH_DATA;
1142266: 337: while (p != a)
branch 0 taken 3%
branch 1 taken 97% (fallthrough)
-: 338: {
16260: 339: if (*p != '\0')
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
138: 340: return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
16122: 341: ++p;
-: 342: }
-: 343:
562934: 344: if (current_type == DBUS_TYPE_BOOLEAN)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 345: {
-: 346: dbus_uint32_t v = _dbus_unpack_uint32 (byte_order,
2829: 347: p);
call 0 returned 100%
2829: 348: if (!(v == 0 || v == 1))
branch 0 taken 26% (fallthrough)
branch 1 taken 74%
branch 2 taken 22% (fallthrough)
branch 3 taken 78%
162: 349: return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE;
-: 350: }
-: 351:
562772: 352: p += alignment;
562772: 353: break;
-: 354:
-: 355: case DBUS_TYPE_ARRAY:
-: 356: case DBUS_TYPE_STRING:
-: 357: case DBUS_TYPE_OBJECT_PATH:
-: 358: {
-: 359: dbus_uint32_t claimed_len;
-: 360:
1091075: 361: a = _DBUS_ALIGN_ADDRESS (p, 4);
1091075: 362: if (a + 4 > end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
915: 363: return DBUS_INVALID_NOT_ENOUGH_DATA;
2257549: 364: while (p != a)
branch 0 taken 7%
branch 1 taken 93% (fallthrough)
-: 365: {
77289: 366: if (*p != '\0')
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
60: 367: return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
77229: 368: ++p;
-: 369: }
-: 370:
1090100: 371: claimed_len = _dbus_unpack_uint32 (byte_order, p);
call 0 returned 100%
1090100: 372: p += 4;
-: 373:
-: 374: /* p may now be == end */
1090100: 375: _dbus_assert (p <= end);
call 0 returned 100%
-: 376:
1090100: 377: if (current_type == DBUS_TYPE_ARRAY)
branch 0 taken 22% (fallthrough)
branch 1 taken 78%
-: 378: {
240940: 379: int array_elem_type = _dbus_type_reader_get_element_type (reader);
call 0 returned 100%
240940: 380: alignment = _dbus_type_get_alignment (array_elem_type);
call 0 returned 100%
240940: 381: p = _DBUS_ALIGN_ADDRESS (p, alignment);
-: 382: }
-: 383:
1090100: 384: if (claimed_len > (unsigned long) (end - p))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
14625: 385: return DBUS_INVALID_LENGTH_OUT_OF_BOUNDS;
-: 386:
1075475: 387: if (current_type == DBUS_TYPE_OBJECT_PATH)
branch 0 taken 18% (fallthrough)
branch 1 taken 82%
-: 388: {
-: 389: DBusString str;
193360: 390: _dbus_string_init_const_len (&str, p, claimed_len);
call 0 returned 100%
193360: 391: if (!_dbus_validate_path (&str, 0,
call 0 returned 100%
call 1 returned 100%
branch 2 taken 3% (fallthrough)
branch 3 taken 97%
-: 392: _dbus_string_get_length (&str)))
6666: 393: return DBUS_INVALID_BAD_PATH;
-: 394:
186694: 395: p += claimed_len;
-: 396: }
882115: 397: else if (current_type == DBUS_TYPE_STRING)
branch 0 taken 73% (fallthrough)
branch 1 taken 27%
-: 398: {
-: 399: DBusString str;
644235: 400: _dbus_string_init_const_len (&str, p, claimed_len);
call 0 returned 100%
644235: 401: if (!_dbus_string_validate_utf8 (&str, 0,
call 0 returned 100%
call 1 returned 100%
branch 2 taken 2% (fallthrough)
branch 3 taken 98%
-: 402: _dbus_string_get_length (&str)))
15447: 403: return DBUS_INVALID_BAD_UTF8_IN_STRING;
-: 404:
628788: 405: p += claimed_len;
-: 406: }
237880: 407: else if (current_type == DBUS_TYPE_ARRAY && claimed_len > 0)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
branch 2 taken 98% (fallthrough)
branch 3 taken 2%
-: 408: {
-: 409: DBusTypeReader sub;
-: 410: DBusValidity validity;
-: 411: const unsigned char *array_end;
-: 412:
233362: 413: if (claimed_len > DBUS_MAXIMUM_ARRAY_LENGTH)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 414: return DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM;
-: 415:
-: 416: /* Remember that the reader is types only, so we can't
-: 417: * use it to iterate over elements. It stays the same
-: 418: * for all elements.
-: 419: */
233362: 420: _dbus_type_reader_recurse (reader, &sub);
call 0 returned 100%
-: 421:
233362: 422: array_end = p + claimed_len;
-: 423:
1376233: 424: while (p < array_end)
branch 0 taken 87%
branch 1 taken 13% (fallthrough)
-: 425: {
-: 426: /* FIXME we are calling a function per array element! very bad
-: 427: * need if (dbus_type_is_fixed(elem_type)) here to just skip
-: 428: * big blocks of ints/bytes/etc.
-: 429: */
-: 430:
992277: 431: validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
call 0 returned 100%
992277: 432: if (validity != DBUS_VALID)
branch 0 taken 8% (fallthrough)
branch 1 taken 92%
82768: 433: return validity;
-: 434: }
-: 435:
150594: 436: if (p != array_end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
1938: 437: return DBUS_INVALID_ARRAY_LENGTH_INCORRECT;
-: 438: }
-: 439:
-: 440: /* check nul termination */
968656: 441: if (current_type != DBUS_TYPE_ARRAY)
branch 0 taken 84% (fallthrough)
branch 1 taken 16%
-: 442: {
815482: 443: if (p == end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
123: 444: return DBUS_INVALID_NOT_ENOUGH_DATA;
-: 445:
815359: 446: if (*p != '\0')
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
7485: 447: return DBUS_INVALID_STRING_MISSING_NUL;
807874: 448: ++p;
-: 449: }
-: 450: }
961048: 451: break;
-: 452:
-: 453: case DBUS_TYPE_SIGNATURE:
-: 454: {
-: 455: dbus_uint32_t claimed_len;
-: 456: DBusString str;
-: 457: DBusValidity validity;
-: 458:
130405: 459: claimed_len = *p;
130405: 460: ++p;
-: 461:
-: 462: /* 1 is for nul termination */
130405: 463: if (claimed_len + 1 > (unsigned long) (end - p))
branch 0 taken 2% (fallthrough)
branch 1 taken 98%
2013: 464: return DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
-: 465:
128392: 466: _dbus_string_init_const_len (&str, p, claimed_len);
call 0 returned 100%
128392: 467: validity =
call 0 returned 100%
call 1 returned 100%
-: 468: _dbus_validate_signature_with_reason (&str, 0,
-: 469: _dbus_string_get_length (&str));
-: 470:
128392: 471: if (validity != DBUS_VALID)
branch 0 taken 3% (fallthrough)
branch 1 taken 97%
4416: 472: return validity;
-: 473:
123976: 474: p += claimed_len;
-: 475:
123976: 476: _dbus_assert (p < end);
call 0 returned 100%
123976: 477: if (*p != DBUS_TYPE_INVALID)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
1125: 478: return DBUS_INVALID_SIGNATURE_MISSING_NUL;
-: 479:
122851: 480: ++p;
-: 481:
122851: 482: _dbus_verbose ("p = %p end = %p claimed_len %u\n", p, end, claimed_len);
call 0 returned 100%
-: 483: }
122851: 484: break;
-: 485:
-: 486: case DBUS_TYPE_VARIANT:
-: 487: {
-: 488: /* 1 byte sig len, sig typecodes, align to
-: 489: * contained-type-boundary, values.
-: 490: */
-: 491:
-: 492: /* In addition to normal signature validation, we need to be sure
-: 493: * the signature contains only a single (possibly container) type.
-: 494: */
-: 495: dbus_uint32_t claimed_len;
-: 496: DBusString sig;
-: 497: DBusTypeReader sub;
-: 498: DBusValidity validity;
-: 499: int contained_alignment;
-: 500: int contained_type;
-: 501: DBusValidity reason;
-: 502:
963214: 503: claimed_len = *p;
963214: 504: ++p;
-: 505:
-: 506: /* + 1 for nul */
963214: 507: if (claimed_len + 1 > (unsigned long) (end - p))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
8325: 508: return DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS;
-: 509:
954889: 510: _dbus_string_init_const_len (&sig, p, claimed_len);
call 0 returned 100%
954889: 511: reason = _dbus_validate_signature_with_reason (&sig, 0,
call 0 returned 100%
call 1 returned 100%
-: 512: _dbus_string_get_length (&sig));
954889: 513: if (!(reason == DBUS_VALID))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 514: {
8008: 515: if (reason == DBUS_VALIDITY_UNKNOWN_OOM_ERROR)
branch 0 taken 57% (fallthrough)
branch 1 taken 43%
4597: 516: return reason;
-: 517: else
3411: 518: return DBUS_INVALID_VARIANT_SIGNATURE_BAD;
-: 519: }
-: 520:
946881: 521: p += claimed_len;
-: 522:
946881: 523: if (*p != DBUS_TYPE_INVALID)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
3327: 524: return DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL;
943554: 525: ++p;
-: 526:
943554: 527: contained_type = _dbus_first_type_in_signature (&sig, 0);
call 0 returned 100%
943554: 528: if (contained_type == DBUS_TYPE_INVALID)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
4875: 529: return DBUS_INVALID_VARIANT_SIGNATURE_EMPTY;
-: 530:
938679: 531: contained_alignment = _dbus_type_get_alignment (contained_type);
call 0 returned 100%
-: 532:
938679: 533: a = _DBUS_ALIGN_ADDRESS (p, contained_alignment);
938679: 534: if (a > end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
42: 535: return DBUS_INVALID_NOT_ENOUGH_DATA;
1886051: 536: while (p != a)
branch 0 taken 1%
branch 1 taken 99% (fallthrough)
-: 537: {
8942: 538: if (*p != '\0')
branch 0 taken 2% (fallthrough)
branch 1 taken 98%
165: 539: return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
8777: 540: ++p;
-: 541: }
-: 542:
938472: 543: _dbus_type_reader_init_types_only (&sub, &sig, 0);
call 0 returned 100%
-: 544:
938472: 545: _dbus_assert (_dbus_type_reader_get_current_type (&sub) != DBUS_TYPE_INVALID);
call 0 returned 100%
call 1 returned 100%
-: 546:
938472: 547: validity = validate_body_helper (&sub, byte_order, FALSE, p, end, &p);
call 0 returned 100%
938472: 548: if (validity != DBUS_VALID)
branch 0 taken 5% (fallthrough)
branch 1 taken 95%
45459: 549: return validity;
-: 550:
893013: 551: if (_dbus_type_reader_next (&sub))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 552: return DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES;
-: 553:
893013: 554: _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_INVALID);
call 0 returned 100%
call 1 returned 100%
-: 555: }
893013: 556: break;
-: 557:
-: 558: case DBUS_TYPE_DICT_ENTRY:
-: 559: case DBUS_TYPE_STRUCT:
-: 560: {
-: 561: DBusTypeReader sub;
-: 562: DBusValidity validity;
-: 563:
987259: 564: a = _DBUS_ALIGN_ADDRESS (p, 8);
987259: 565: if (a > end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
54: 566: return DBUS_INVALID_NOT_ENOUGH_DATA;
4248375: 567: while (p != a)
branch 0 taken 70%
branch 1 taken 30% (fallthrough)
-: 568: {
2286214: 569: if (*p != '\0')
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
12249: 570: return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
2273965: 571: ++p;
-: 572: }
-: 573:
974956: 574: _dbus_type_reader_recurse (reader, &sub);
call 0 returned 100%
-: 575:
974956: 576: validity = validate_body_helper (&sub, byte_order, TRUE, p, end, &p);
call 0 returned 100%
974956: 577: if (validity != DBUS_VALID)
branch 0 taken 7% (fallthrough)
branch 1 taken 93%
71338: 578: return validity;
-: 579: }
903618: 580: break;
-: 581:
-: 582: default:
#####: 583: _dbus_assert_not_reached ("invalid typecode in supposedly-validated signature");
call 0 never executed
-: 584: break;
-: 585: }
-: 586:
-: 587:#if 0
-: 588: _dbus_verbose (" validated value of type %s type reader %p type_pos %d p %p end %p %d remain\n",
-: 589: _dbus_type_to_string (current_type), reader, reader->type_pos, p, end,
-: 590: (int) (end - p));
-: 591:#endif
-: 592:
5269141: 593: if (p > end)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 594: {
843: 595: _dbus_verbose ("not enough data!!! p = %p end = %p end-p = %d\n",
call 0 returned 100%
-: 596: p, end, (int) (end - p));
843: 597: return DBUS_INVALID_NOT_ENOUGH_DATA;
-: 598: }
-: 599:
5268298: 600: if (walk_reader_to_end)
branch 0 taken 34% (fallthrough)
branch 1 taken 66%
3465776: 601: _dbus_type_reader_next (reader);
call 0 returned 100%
-: 602: else
1802522: 603: break;
-: 604: }
-: 605:
2947480: 606: if (new_p)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
2947480: 607: *new_p = p;
-: 608:
2947480: 609: return DBUS_VALID;
-: 610:}
-: 611:
-: 612:/**
-: 613: * Verifies that the range of value_str from value_pos to value_end is
-: 614: * a legitimate value of type expected_signature. If this function
-: 615: * returns #TRUE, it will be safe to iterate over the values with
-: 616: * #DBusTypeReader. The signature is assumed to be already valid.
-: 617: *
-: 618: * If bytes_remaining is not #NULL, then leftover bytes will be stored
-: 619: * there and #DBUS_VALID returned. If it is #NULL, then
-: 620: * #DBUS_INVALID_TOO_MUCH_DATA will be returned if bytes are left
-: 621: * over.
-: 622: *
-: 623: * @param expected_signature the expected types in the value_str
-: 624: * @param expected_signature_start where in expected_signature is the signature
-: 625: * @param byte_order the byte order
-: 626: * @param bytes_remaining place to store leftover bytes
-: 627: * @param value_str the string containing the body
-: 628: * @param value_pos where the values start
-: 629: * @param len length of values after value_pos
-: 630: * @returns #DBUS_VALID if valid, reason why invalid otherwise
-: 631: */
-: 632:DBusValidity
-: 633:_dbus_validate_body_with_reason (const DBusString *expected_signature,
-: 634: int expected_signature_start,
-: 635: int byte_order,
-: 636: int *bytes_remaining,
-: 637: const DBusString *value_str,
-: 638: int value_pos,
-: 639: int len)
function _dbus_validate_body_with_reason called 335115 returned 100% blocks executed 100%
335115: 640:{
-: 641: DBusTypeReader reader;
-: 642: const unsigned char *p;
-: 643: const unsigned char *end;
-: 644: DBusValidity validity;
-: 645:
335115: 646: _dbus_assert (len >= 0);
call 0 returned 100%
335115: 647: _dbus_assert (value_pos >= 0);
call 0 returned 100%
335115: 648: _dbus_assert (value_pos <= _dbus_string_get_length (value_str) - len);
call 0 returned 100%
call 1 returned 100%
-: 649:
335115: 650: _dbus_verbose ("validating body from pos %d len %d sig '%s'\n",
call 0 returned 100%
call 1 returned 100%
-: 651: value_pos, len, _dbus_string_get_const_data_len (expected_signature,
-: 652: expected_signature_start,
-: 653: 0));
-: 654:
335115: 655: _dbus_type_reader_init_types_only (&reader,
call 0 returned 100%
-: 656: expected_signature, expected_signature_start);
-: 657:
335115: 658: p = _dbus_string_get_const_data_len (value_str, value_pos, len);
call 0 returned 100%
335115: 659: end = p + len;
-: 660:
335115: 661: validity = validate_body_helper (&reader, byte_order, TRUE, p, end, &p);
call 0 returned 100%
335115: 662: if (validity != DBUS_VALID)
branch 0 taken 28% (fallthrough)
branch 1 taken 72%
93775: 663: return validity;
-: 664:
241340: 665: if (bytes_remaining)
branch 0 taken 56% (fallthrough)
branch 1 taken 44%
-: 666: {
134329: 667: *bytes_remaining = end - p;
134329: 668: return DBUS_VALID;
-: 669: }
107011: 670: else if (p < end)
branch 0 taken 6% (fallthrough)
branch 1 taken 94%
5928: 671: return DBUS_INVALID_TOO_MUCH_DATA;
-: 672: else
-: 673: {
101083: 674: _dbus_assert (p == end);
call 0 returned 100%
101083: 675: return DBUS_VALID;
-: 676: }
-: 677:}
-: 678:
-: 679:/**
-: 680: * Determine wether the given character is valid as the first character
-: 681: * in a name.
-: 682: */
-: 683:#define VALID_INITIAL_NAME_CHARACTER(c) \
-: 684: ( ((c) >= 'A' && (c) <= 'Z') || \
-: 685: ((c) >= 'a' && (c) <= 'z') || \
-: 686: ((c) == '_') )
-: 687:
-: 688:/**
-: 689: * Determine wether the given character is valid as a second or later
-: 690: * character in a name
-: 691: */
-: 692:#define VALID_NAME_CHARACTER(c) \
-: 693: ( ((c) >= '0' && (c) <= '9') || \
-: 694: ((c) >= 'A' && (c) <= 'Z') || \
-: 695: ((c) >= 'a' && (c) <= 'z') || \
-: 696: ((c) == '_') )
-: 697:
-: 698:/**
-: 699: * Checks that the given range of the string is a valid object path
-: 700: * name in the D-BUS protocol. Part of the validation ensures that
-: 701: * the object path contains only ASCII.
-: 702: *
-: 703: * @todo this is inconsistent with most of DBusString in that
-: 704: * it allows a start,len range that extends past the string end.
-: 705: *
-: 706: * @todo change spec to disallow more things, such as spaces in the
-: 707: * path name
-: 708: *
-: 709: * @param str the string
-: 710: * @param start first byte index to check
-: 711: * @param len number of bytes to check
-: 712: * @returns #TRUE if the byte range exists and is a valid name
-: 713: */
-: 714:dbus_bool_t
-: 715:_dbus_validate_path (const DBusString *str,
-: 716: int start,
-: 717: int len)
function _dbus_validate_path called 311189 returned 100% blocks executed 97%
311189: 718:{
-: 719: const unsigned char *s;
-: 720: const unsigned char *end;
-: 721: const unsigned char *last_slash;
-: 722:
311189: 723: _dbus_assert (start >= 0);
call 0 returned 100%
311189: 724: _dbus_assert (len >= 0);
call 0 returned 100%
311189: 725: _dbus_assert (start <= _dbus_string_get_length (str));
call 0 returned 100%
call 1 returned 100%
-: 726:
311189: 727: if (len > _dbus_string_get_length (str) - start)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 728: return FALSE;
-: 729:
311189: 730: if (len == 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
775: 731: return FALSE;
-: 732:
310414: 733: s = _dbus_string_get_const_data (str) + start;
call 0 returned 100%
310414: 734: end = s + len;
-: 735:
310414: 736: if (*s != '/')
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
4420: 737: return FALSE;
305994: 738: last_slash = s;
305994: 739: ++s;
-: 740:
3086541: 741: while (s != end)
branch 0 taken 89%
branch 1 taken 11% (fallthrough)
-: 742: {
2476034: 743: if (*s == '/')
branch 0 taken 10% (fallthrough)
branch 1 taken 90%
-: 744: {
250810: 745: if ((s - last_slash) < 2)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
2: 746: return FALSE; /* no empty path components allowed */
-: 747:
250808: 748: last_slash = s;
-: 749: }
-: 750: else
-: 751: {
2225224: 752: if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 100% (fallthrough)
branch 3 taken 0%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 89% (fallthrough)
branch 7 taken 11%
branch 8 taken 99% (fallthrough)
branch 9 taken 1%
branch 10 taken 0% (fallthrough)
branch 11 taken 100%
branch 12 taken 100% (fallthrough)
branch 13 taken 0%
1479: 753: return FALSE;
-: 754: }
-: 755:
2474553: 756: ++s;
-: 757: }
-: 758:
304513: 759: if ((end - last_slash) < 2 &&
branch 0 taken 60% (fallthrough)
branch 1 taken 40%
branch 2 taken 1% (fallthrough)
branch 3 taken 99%
-: 760: len > 1)
2: 761: return FALSE; /* trailing slash not allowed unless the string is "/" */
-: 762:
304511: 763: return TRUE;
-: 764:}
-: 765:
-: 766:/**
-: 767: * Checks that the given range of the string is a valid interface name
-: 768: * in the D-BUS protocol. This includes a length restriction and an
-: 769: * ASCII subset, see the specification.
-: 770: *
-: 771: * @todo this is inconsistent with most of DBusString in that
-: 772: * it allows a start,len range that extends past the string end.
-: 773: *
-: 774: * @param str the string
-: 775: * @param start first byte index to check
-: 776: * @param len number of bytes to check
-: 777: * @returns #TRUE if the byte range exists and is a valid name
-: 778: */
-: 779:dbus_bool_t
-: 780:_dbus_validate_interface (const DBusString *str,
-: 781: int start,
-: 782: int len)
function _dbus_validate_interface called 253744 returned 100% blocks executed 100%
253744: 783:{
-: 784: const unsigned char *s;
-: 785: const unsigned char *end;
-: 786: const unsigned char *iface;
-: 787: const unsigned char *last_dot;
-: 788:
253744: 789: _dbus_assert (start >= 0);
call 0 returned 100%
253744: 790: _dbus_assert (len >= 0);
call 0 returned 100%
253744: 791: _dbus_assert (start <= _dbus_string_get_length (str));
call 0 returned 100%
call 1 returned 100%
-: 792:
253744: 793: if (len > _dbus_string_get_length (str) - start)
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
2: 794: return FALSE;
-: 795:
253742: 796: if (len > DBUS_MAXIMUM_NAME_LENGTH)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
2: 797: return FALSE;
-: 798:
253740: 799: if (len == 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
4: 800: return FALSE;
-: 801:
253736: 802: last_dot = NULL;
253736: 803: iface = _dbus_string_get_const_data (str) + start;
call 0 returned 100%
253736: 804: end = iface + len;
253736: 805: s = iface;
-: 806:
-: 807: /* check special cases of first char so it doesn't have to be done
-: 808: * in the loop. Note we know len > 0
-: 809: */
253736: 810: if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
8: 811: return FALSE;
253728: 812: else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 99% (fallthrough)
branch 3 taken 1%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 0% (fallthrough)
branch 7 taken 100%
branch 8 taken 100% (fallthrough)
branch 9 taken 0%
15: 813: return FALSE;
-: 814: else
253713: 815: ++s;
-: 816:
3599251: 817: while (s != end)
branch 0 taken 93%
branch 1 taken 7% (fallthrough)
-: 818: {
3094880: 819: if (*s == '.')
branch 0 taken 18% (fallthrough)
branch 1 taken 82%
-: 820: {
564242: 821: if (_DBUS_UNLIKELY ((s + 1) == end))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
2: 822: return FALSE;
564240: 823: else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*(s + 1))))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 44% (fallthrough)
branch 3 taken 56%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 1% (fallthrough)
branch 7 taken 99%
branch 8 taken 100% (fallthrough)
branch 9 taken 0%
1452: 824: return FALSE;
562788: 825: last_dot = s;
562788: 826: ++s; /* we just validated the next char, so skip two */
-: 827: }
2530638: 828: else if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 99% (fallthrough)
branch 3 taken 1%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 93% (fallthrough)
branch 7 taken 7%
branch 8 taken 99% (fallthrough)
branch 9 taken 1%
branch 10 taken 0% (fallthrough)
branch 11 taken 100%
branch 12 taken 100% (fallthrough)
branch 13 taken 0%
-: 829: {
1601: 830: return FALSE;
-: 831: }
-: 832:
3091825: 833: ++s;
-: 834: }
-: 835:
250658: 836: if (_DBUS_UNLIKELY (last_dot == NULL))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
362: 837: return FALSE;
-: 838:
250296: 839: return TRUE;
-: 840:}
-: 841:
-: 842:/**
-: 843: * Checks that the given range of the string is a valid member name
-: 844: * in the D-BUS protocol. This includes a length restriction, etc.,
-: 845: * see the specification.
-: 846: *
-: 847: * @todo this is inconsistent with most of DBusString in that
-: 848: * it allows a start,len range that extends past the string end.
-: 849: *
-: 850: * @param str the string
-: 851: * @param start first byte index to check
-: 852: * @param len number of bytes to check
-: 853: * @returns #TRUE if the byte range exists and is a valid name
-: 854: */
-: 855:dbus_bool_t
-: 856:_dbus_validate_member (const DBusString *str,
-: 857: int start,
-: 858: int len)
function _dbus_validate_member called 224350 returned 100% blocks executed 100%
224350: 859:{
-: 860: const unsigned char *s;
-: 861: const unsigned char *end;
-: 862: const unsigned char *member;
-: 863:
224350: 864: _dbus_assert (start >= 0);
call 0 returned 100%
224350: 865: _dbus_assert (len >= 0);
call 0 returned 100%
224350: 866: _dbus_assert (start <= _dbus_string_get_length (str));
call 0 returned 100%
call 1 returned 100%
-: 867:
224350: 868: if (len > _dbus_string_get_length (str) - start)
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
1: 869: return FALSE;
-: 870:
224349: 871: if (len > DBUS_MAXIMUM_NAME_LENGTH)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
1: 872: return FALSE;
-: 873:
224348: 874: if (len == 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
1: 875: return FALSE;
-: 876:
224347: 877: member = _dbus_string_get_const_data (str) + start;
call 0 returned 100%
224347: 878: end = member + len;
224347: 879: s = member;
-: 880:
-: 881: /* check special cases of first char so it doesn't have to be done
-: 882: * in the loop. Note we know len > 0
-: 883: */
-: 884:
224347: 885: if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 1% (fallthrough)
branch 3 taken 99%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 0% (fallthrough)
branch 7 taken 100%
branch 8 taken 86% (fallthrough)
branch 9 taken 14%
6: 886: return FALSE;
-: 887: else
224341: 888: ++s;
-: 889:
1975190: 890: while (s != end)
branch 0 taken 87%
branch 1 taken 13% (fallthrough)
-: 891: {
1527233: 892: if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 99% (fallthrough)
branch 3 taken 1%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 90% (fallthrough)
branch 7 taken 10%
branch 8 taken 99% (fallthrough)
branch 9 taken 1%
branch 10 taken 0% (fallthrough)
branch 11 taken 100%
branch 12 taken 100% (fallthrough)
branch 13 taken 0%
-: 893: {
725: 894: return FALSE;
-: 895: }
-: 896:
1526508: 897: ++s;
-: 898: }
-: 899:
223616: 900: return TRUE;
-: 901:}
-: 902:
-: 903:/**
-: 904: * Checks that the given range of the string is a valid error name
-: 905: * in the D-BUS protocol. This includes a length restriction, etc.,
-: 906: * see the specification.
-: 907: *
-: 908: * @todo this is inconsistent with most of DBusString in that
-: 909: * it allows a start,len range that extends past the string end.
-: 910: *
-: 911: * @param str the string
-: 912: * @param start first byte index to check
-: 913: * @param len number of bytes to check
-: 914: * @returns #TRUE if the byte range exists and is a valid name
-: 915: */
-: 916:dbus_bool_t
-: 917:_dbus_validate_error_name (const DBusString *str,
-: 918: int start,
-: 919: int len)
function _dbus_validate_error_name called 24004 returned 100% blocks executed 100%
24004: 920:{
-: 921: /* Same restrictions as interface name at the moment */
24004: 922: return _dbus_validate_interface (str, start, len);
call 0 returned 100%
-: 923:}
-: 924:
-: 925:/**
-: 926: * Determine wether the given character is valid as the first character
-: 927: * in a bus name.
-: 928: */
-: 929:#define VALID_INITIAL_BUS_NAME_CHARACTER(c) \
-: 930: ( ((c) >= 'A' && (c) <= 'Z') || \
-: 931: ((c) >= 'a' && (c) <= 'z') || \
-: 932: ((c) == '_') || ((c) == '-'))
-: 933:
-: 934:/**
-: 935: * Determine wether the given character is valid as a second or later
-: 936: * character in a bus name
-: 937: */
-: 938:#define VALID_BUS_NAME_CHARACTER(c) \
-: 939: ( ((c) >= '0' && (c) <= '9') || \
-: 940: ((c) >= 'A' && (c) <= 'Z') || \
-: 941: ((c) >= 'a' && (c) <= 'z') || \
-: 942: ((c) == '_') || ((c) == '-'))
-: 943:
-: 944:/**
-: 945: * Checks that the given range of the string is a valid bus name in
-: 946: * the D-BUS protocol. This includes a length restriction, etc., see
-: 947: * the specification.
-: 948: *
-: 949: * @todo this is inconsistent with most of DBusString in that
-: 950: * it allows a start,len range that extends past the string end.
-: 951: *
-: 952: * @param str the string
-: 953: * @param start first byte index to check
-: 954: * @param len number of bytes to check
-: 955: * @returns #TRUE if the byte range exists and is a valid name
-: 956: */
-: 957:dbus_bool_t
-: 958:_dbus_validate_bus_name (const DBusString *str,
-: 959: int start,
-: 960: int len)
function _dbus_validate_bus_name called 345311 returned 100% blocks executed 100%
345311: 961:{
-: 962: const unsigned char *s;
-: 963: const unsigned char *end;
-: 964: const unsigned char *iface;
-: 965: const unsigned char *last_dot;
-: 966:
345311: 967: _dbus_assert (start >= 0);
call 0 returned 100%
345311: 968: _dbus_assert (len >= 0);
call 0 returned 100%
345311: 969: _dbus_assert (start <= _dbus_string_get_length (str));
call 0 returned 100%
call 1 returned 100%
-: 970:
345311: 971: if (len > _dbus_string_get_length (str) - start)
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
1: 972: return FALSE;
-: 973:
345310: 974: if (len > DBUS_MAXIMUM_NAME_LENGTH)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
2: 975: return FALSE;
-: 976:
345308: 977: if (len == 0)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
3: 978: return FALSE;
-: 979:
345305: 980: last_dot = NULL;
345305: 981: iface = _dbus_string_get_const_data (str) + start;
call 0 returned 100%
345305: 982: end = iface + len;
345305: 983: s = iface;
-: 984:
-: 985: /* check special cases of first char so it doesn't have to be done
-: 986: * in the loop. Note we know len > 0
-: 987: */
345305: 988: if (*s == ':')
branch 0 taken 25% (fallthrough)
branch 1 taken 75%
-: 989: {
-: 990: /* unique name */
87264: 991: ++s;
606730: 992: while (s != end)
branch 0 taken 83%
branch 1 taken 17% (fallthrough)
-: 993: {
432208: 994: if (*s == '.')
branch 0 taken 20% (fallthrough)
branch 1 taken 80%
-: 995: {
87262: 996: if (_DBUS_UNLIKELY ((s + 1) == end))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
2: 997: return FALSE;
87260: 998: if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*(s + 1))))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 1% (fallthrough)
branch 3 taken 99%
branch 4 taken 63% (fallthrough)
branch 5 taken 38%
branch 6 taken 100% (fallthrough)
branch 7 taken 0%
branch 8 taken 63% (fallthrough)
branch 9 taken 38%
branch 10 taken 0% (fallthrough)
branch 11 taken 100%
branch 12 taken 100% (fallthrough)
branch 13 taken 0%
branch 14 taken 100% (fallthrough)
branch 15 taken 0%
3: 999: return FALSE;
87257: 1000: ++s; /* we just validated the next char, so skip two */
-: 1001: }
344946: 1002: else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 1% (fallthrough)
branch 3 taken 99%
branch 4 taken 98% (fallthrough)
branch 5 taken 3%
branch 6 taken 100% (fallthrough)
branch 7 taken 0%
branch 8 taken 98% (fallthrough)
branch 9 taken 3%
branch 10 taken 0% (fallthrough)
branch 11 taken 100%
branch 12 taken 100% (fallthrough)
branch 13 taken 0%
branch 14 taken 100% (fallthrough)
branch 15 taken 0%
-: 1003: {
1: 1004: return FALSE;
-: 1005: }
-: 1006:
432202: 1007: ++s;
-: 1008: }
-: 1009:
87258: 1010: return TRUE;
-: 1011: }
258041: 1012: else if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
4: 1013: return FALSE;
258037: 1014: else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 99% (fallthrough)
branch 3 taken 1%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 0% (fallthrough)
branch 7 taken 100%
branch 8 taken 100% (fallthrough)
branch 9 taken 0%
branch 10 taken 100% (fallthrough)
branch 11 taken 0%
7: 1015: return FALSE;
-: 1016: else
258030: 1017: ++s;
-: 1018:
3463304: 1019: while (s != end)
branch 0 taken 92%
branch 1 taken 8% (fallthrough)
-: 1020: {
2947617: 1021: if (*s == '.')
branch 0 taken 18% (fallthrough)
branch 1 taken 82%
-: 1022: {
525475: 1023: if (_DBUS_UNLIKELY ((s + 1) == end))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
1: 1024: return FALSE;
525474: 1025: else if (_DBUS_UNLIKELY (!VALID_INITIAL_BUS_NAME_CHARACTER (*(s + 1))))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 50% (fallthrough)
branch 3 taken 50%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 0% (fallthrough)
branch 7 taken 100%
branch 8 taken 100% (fallthrough)
branch 9 taken 0%
branch 10 taken 100% (fallthrough)
branch 11 taken 0%
366: 1026: return FALSE;
525108: 1027: last_dot = s;
525108: 1028: ++s; /* we just validated the next char, so skip two */
-: 1029: }
2422142: 1030: else if (_DBUS_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s)))
branch 0 taken 99% (fallthrough)
branch 1 taken 1%
branch 2 taken 99% (fallthrough)
branch 3 taken 1%
branch 4 taken 99% (fallthrough)
branch 5 taken 1%
branch 6 taken 93% (fallthrough)
branch 7 taken 7%
branch 8 taken 99% (fallthrough)
branch 9 taken 1%
branch 10 taken 0% (fallthrough)
branch 11 taken 100%
branch 12 taken 100% (fallthrough)
branch 13 taken 0%
branch 14 taken 100% (fallthrough)
branch 15 taken 0%
-: 1031: {
6: 1032: return FALSE;
-: 1033: }
-: 1034:
2947244: 1035: ++s;
-: 1036: }
-: 1037:
257657: 1038: if (_DBUS_UNLIKELY (last_dot == NULL))
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
1: 1039: return FALSE;
-: 1040:
257656: 1041: return TRUE;
-: 1042:}
-: 1043:
-: 1044:/**
-: 1045: * Checks that the given range of the string is a valid message type
-: 1046: * signature in the D-BUS protocol.
-: 1047: *
-: 1048: * @todo this is inconsistent with most of DBusString in that
-: 1049: * it allows a start,len range that extends past the string end.
-: 1050: *
-: 1051: * @param str the string
-: 1052: * @param start first byte index to check
-: 1053: * @param len number of bytes to check
-: 1054: * @returns #TRUE if the byte range exists and is a valid signature
-: 1055: */
-: 1056:dbus_bool_t
-: 1057:_dbus_validate_signature (const DBusString *str,
-: 1058: int start,
-: 1059: int len)
function _dbus_validate_signature called 168 returned 100% blocks executed 100%
168: 1060:{
168: 1061: _dbus_assert (start >= 0);
call 0 returned 100%
168: 1062: _dbus_assert (start <= _dbus_string_get_length (str));
call 0 returned 100%
call 1 returned 100%
168: 1063: _dbus_assert (len >= 0);
call 0 returned 100%
-: 1064:
168: 1065: if (len > _dbus_string_get_length (str) - start)
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
1: 1066: return FALSE;
-: 1067:
167: 1068: return _dbus_validate_signature_with_reason (str, start, len) == DBUS_VALID;
call 0 returned 100%
-: 1069:}
-: 1070:
-: 1071:/** define _dbus_check_is_valid_path() */
function _dbus_check_is_valid_path called 113993 returned 100% blocks executed 86%
113993: 1072:DEFINE_DBUS_NAME_CHECK(path);
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
call 2 returned 100%
call 3 returned 100%
call 4 returned 100%
-: 1073:/** define _dbus_check_is_valid_interface() */
function _dbus_check_is_valid_interface called 113993 returned 100% blocks executed 86%
113993: 1074:DEFINE_DBUS_NAME_CHECK(interface);
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
call 2 returned 100%
call 3 returned 100%
call 4 returned 100%
-: 1075:/** define _dbus_check_is_valid_member() */
function _dbus_check_is_valid_member called 113993 returned 100% blocks executed 86%
113993: 1076:DEFINE_DBUS_NAME_CHECK(member);
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
call 2 returned 100%
call 3 returned 100%
call 4 returned 100%
-: 1077:/** define _dbus_check_is_valid_error_name() */
function _dbus_check_is_valid_error_name called 16171 returned 100% blocks executed 86%
16171: 1078:DEFINE_DBUS_NAME_CHECK(error_name);
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
call 2 returned 100%
call 3 returned 100%
call 4 returned 100%
-: 1079:/** define _dbus_check_is_valid_bus_name() */
function _dbus_check_is_valid_bus_name called 193554 returned 100% blocks executed 86%
193554: 1080:DEFINE_DBUS_NAME_CHECK(bus_name);
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
call 2 returned 100%
call 3 returned 100%
call 4 returned 100%
-: 1081:/** define _dbus_check_is_valid_signature() */
function _dbus_check_is_valid_signature called 0 returned 0% blocks executed 0%
#####: 1082:DEFINE_DBUS_NAME_CHECK(signature);
branch 0 never executed
branch 1 never executed
call 2 never executed
call 3 never executed
call 4 never executed
-: 1083:
-: 1084:/** @} */
-: 1085:
-: 1086:/* tests in dbus-marshal-validate-util.c */