(linenum→info "unix/slp.c:2238")

dbus/1.0.2/dbus/dbus-marshal-validate.h

    1: /* -*- mode: C; c-file-style: "gnu" -*- */
    2: /* dbus-marshal-validate.h  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: #ifndef DBUS_MARSHAL_VALIDATE_H
   25: #define DBUS_MARSHAL_VALIDATE_H
   26: 
   27: #include <config.h>
   28: 
   29: #ifndef PACKAGE
   30: #error "config.h not included here"
   31: #endif
   32: 
   33: /**
   34:  * @addtogroup DBusMarshal
   35:  *
   36:  * @{
   37:  */
   38: 
   39: /**
   40:  * This is used rather than a bool for high visibility
   41:  */
   42: typedef enum
   43: {
   44:   DBUS_VALIDATION_MODE_WE_TRUST_THIS_DATA_ABSOLUTELY,
   45:   DBUS_VALIDATION_MODE_DATA_IS_UNTRUSTED
   46: } DBusValidationMode;
   47: 
   48: /**
   49:  * This is primarily used in unit testing, so we can verify that each
   50:  * invalid message is invalid for the expected reasons. Thus we really
   51:  * want a distinct enum value for every codepath leaving the validator
   52:  * functions. Enum values are specified manually for ease of debugging
   53:  * (so you can see the enum value given a printf)
   54:  */
   55: typedef enum
   56: {
   57: #define _DBUS_NEGATIVE_VALIDITY_COUNT 4
   58:   DBUS_VALIDITY_UNKNOWN_OOM_ERROR = -4, /**< can't determine validity due to OOM */
   59:   DBUS_INVALID_FOR_UNKNOWN_REASON = -3,
   60:   DBUS_VALID_BUT_INCOMPLETE = -2,
   61:   DBUS_VALIDITY_UNKNOWN = -1,
   62:   DBUS_VALID = 0, /**< the data is valid */
   63:   DBUS_INVALID_UNKNOWN_TYPECODE = 1,
   64:   DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE = 2,
   65:   DBUS_INVALID_SIGNATURE_TOO_LONG = 3, /* this one is impossible right now since
   66:                                         * you can't put a too-long value in a byte
   67:                                         */
   68:   DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION = 4,
   69:   DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION = 5,
   70:   DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED = 6,
   71:   DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED = 7,
   72:   DBUS_INVALID_STRUCT_HAS_NO_FIELDS = 8,
   73:   DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL = 9,
   74:   DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE = 10,
   75:   DBUS_INVALID_NOT_ENOUGH_DATA = 11,
   76:   DBUS_INVALID_TOO_MUCH_DATA = 12, /**< trailing junk makes it invalid */
   77:   DBUS_INVALID_BAD_BYTE_ORDER = 13,
   78:   DBUS_INVALID_BAD_PROTOCOL_VERSION = 14,
   79:   DBUS_INVALID_BAD_MESSAGE_TYPE = 15,
   80:   DBUS_INVALID_BAD_SERIAL = 16,
   81:   DBUS_INVALID_INSANE_FIELDS_ARRAY_LENGTH = 17,
   82:   DBUS_INVALID_INSANE_BODY_LENGTH = 18,
   83:   DBUS_INVALID_MESSAGE_TOO_LONG = 19,
   84:   DBUS_INVALID_HEADER_FIELD_CODE = 20,
   85:   DBUS_INVALID_HEADER_FIELD_HAS_WRONG_TYPE = 21,
   86:   DBUS_INVALID_USES_LOCAL_INTERFACE = 22,
   87:   DBUS_INVALID_USES_LOCAL_PATH = 23,
   88:   DBUS_INVALID_HEADER_FIELD_APPEARS_TWICE = 24,
   89:   DBUS_INVALID_BAD_DESTINATION = 25,
   90:   DBUS_INVALID_BAD_INTERFACE = 26,
   91:   DBUS_INVALID_BAD_MEMBER = 27,
   92:   DBUS_INVALID_BAD_ERROR_NAME = 28,
   93:   DBUS_INVALID_BAD_SENDER = 29,
   94:   DBUS_INVALID_MISSING_PATH = 30,
   95:   DBUS_INVALID_MISSING_INTERFACE = 31,
   96:   DBUS_INVALID_MISSING_MEMBER = 32,
   97:   DBUS_INVALID_MISSING_ERROR_NAME = 33,
   98:   DBUS_INVALID_MISSING_REPLY_SERIAL = 34,
   99:   DBUS_INVALID_LENGTH_OUT_OF_BOUNDS = 35,
  100:   DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM = 36,
  101:   DBUS_INVALID_BAD_PATH = 37,
  102:   DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 38,
  103:   DBUS_INVALID_BAD_UTF8_IN_STRING = 39,
  104:   DBUS_INVALID_ARRAY_LENGTH_INCORRECT = 40,
  105:   DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 41,
  106:   DBUS_INVALID_VARIANT_SIGNATURE_BAD = 42,
  107:   DBUS_INVALID_VARIANT_SIGNATURE_EMPTY = 43,
  108:   DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 44,
  109:   DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 45,
  110:   DBUS_INVALID_STRING_MISSING_NUL = 46,
  111:   DBUS_INVALID_SIGNATURE_MISSING_NUL = 47,
  112:   DBUS_INVALID_EXCEEDED_MAXIMUM_DICT_ENTRY_RECURSION = 48,
  113:   DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED = 49,
  114:   DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED = 50,
  115:   DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS = 51,
  116:   DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD = 52,
  117:   DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS = 53,
  118:   DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY = 54,
  119:   DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE = 55,
  120:   DBUS_VALIDITY_LAST
  121: } DBusValidity;
  122: 
  123: DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,
  124:                                                    int               type_pos,
  125:                                                    int               len);
  126: DBusValidity _dbus_validate_body_with_reason      (const DBusString *expected_signature,
  127:                                                    int               expected_signature_start,
  128:                                                    int               byte_order,
  129:                                                    int              *bytes_remaining,
  130:                                                    const DBusString *value_str,
  131:                                                    int               value_pos,
  132:                                                    int               len);
  133: 
  134: dbus_bool_t _dbus_validate_path       (const DBusString *str,
  135:                                        int               start,
  136:                                        int               len);
  137: dbus_bool_t _dbus_validate_interface  (const DBusString *str,
  138:                                        int               start,
  139:                                        int               len);
  140: dbus_bool_t _dbus_validate_member     (const DBusString *str,
  141:                                        int               start,
  142:                                        int               len);
  143: dbus_bool_t _dbus_validate_error_name (const DBusString *str,
  144:                                        int               start,
  145:                                        int               len);
  146: dbus_bool_t _dbus_validate_bus_name   (const DBusString *str,
  147:                                        int               start,
  148:                                        int               len);
  149: dbus_bool_t _dbus_validate_signature  (const DBusString *str,
  150:                                        int               start,
  151:                                        int               len);
  152: 
  153: #ifdef DBUS_DISABLE_CHECKS
  154: 
  155: /* Be sure they don't exist, since we don't want to use them outside of checks
  156:  * and so we want the compile failure.
  157:  */
  158: #define DECLARE_DBUS_NAME_CHECK(what)
  159: #define DEFINE_DBUS_NAME_CHECK(what)
  160: 
  161: #else /* !DBUS_DISABLE_CHECKS */
  162: 
  163: /** A name check is used in _dbus_return_if_fail(), it's not suitable
  164:  * for validating untrusted data. use _dbus_validate_whatever for that.
  165:  */
  166: #define DECLARE_DBUS_NAME_CHECK(what) \
  167: dbus_bool_t _dbus_check_is_valid_##what (const char *name)
  168: 
  169: /** Define a name check to be used in _dbus_return_if_fail() statements.
  170:  */
  171: #define DEFINE_DBUS_NAME_CHECK(what)                                    \
  172: dbus_bool_t                                                             \
  173: _dbus_check_is_valid_##what (const char *name)                          \
  174: {                                                                       \
  175:   DBusString str;                                                       \
  176:                                                                         \
  177:   if (name == NULL)                                                     \
  178:     return FALSE;                                                       \
  179:                                                                         \
  180:   _dbus_string_init_const (&str, name);                                 \
  181:   return _dbus_validate_##what (&str, 0,                                \
  182:                                 _dbus_string_get_length (&str));        \
  183: }
  184: #endif /* !DBUS_DISABLE_CHECKS */
  185: 
  186: /** defines _dbus_check_is_valid_path() */
  187: DECLARE_DBUS_NAME_CHECK(path);
  188: /** defines _dbus_check_is_valid_interface() */
  189: DECLARE_DBUS_NAME_CHECK(interface);
  190: /** defines _dbus_check_is_valid_member() */
  191: DECLARE_DBUS_NAME_CHECK(member);
  192: /** defines _dbus_check_is_valid_error_name() */
  193: DECLARE_DBUS_NAME_CHECK(error_name);
  194: /** defines _dbus_check_is_valid_bus_name() */
  195: DECLARE_DBUS_NAME_CHECK(bus_name);
  196: /** defines _dbus_check_is_valid_signature() */
  197: DECLARE_DBUS_NAME_CHECK(signature);
  198: 
  199: /** @} */
  200: 
  201: #endif /* DBUS_MARSHAL_VALIDATE_H */
Syntax (Markdown)