diff --git a/src/classic/sdp_util.c b/src/classic/sdp_util.c index 97fb5fc11..8f64605eb 100644 --- a/src/classic/sdp_util.c +++ b/src/classic/sdp_util.c @@ -391,6 +391,36 @@ bool sdp_attribute_list_contains_id(uint8_t *attributeIDList, uint16_t attribute return attributeID_search.result; } +static int sdp_traversal_attribute_list_valie(uint8_t * element, de_type_t type, de_size_t size, void *my_context) { + bool ok = true; + if (type == DE_UINT) { + ok = false; + } + if ((size != DE_SIZE_16) && (size != DE_SIZE_32)) { + ok = false; + } + if (size == DE_SIZE_32){ + uint16_t lower = big_endian_read_16(element, 1); + uint16_t higher = big_endian_read_16(element, 3); + if (lower > higher){ + ok = false; + } + } + if (ok){ + return 0; + } else { + *(bool *)my_context = false; + return 0; + } +} + +bool sdp_attribute_list_valid(uint8_t *attributeIDList){ + bool attribute_list_valid = true; + de_traverse_sequence(attributeIDList, sdp_traversal_attribute_list_valie, &attribute_list_valid); + return attribute_list_valid; +} + + // MARK: Append Attributes for AttributeIDList // pre: buffer contains DES with 2 byte length field struct sdp_context_append_attributes { diff --git a/src/classic/sdp_util.h b/src/classic/sdp_util.h index bded4afde..1cab50c9b 100644 --- a/src/classic/sdp_util.h +++ b/src/classic/sdp_util.h @@ -145,6 +145,7 @@ bool sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *se uint16_t sdp_get_filtered_size(uint8_t *record, uint8_t *attributeIDList); bool sdp_filter_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startOffset, uint16_t maxBytes, uint16_t *usedBytes, uint8_t *buffer); bool sdp_attribute_list_contains_id(uint8_t *attributeIDList, uint16_t attributeID); +bool sdp_attribute_list_valid(uint8_t *attributeIDList); /* * @brief Returns service search pattern for given UUID-16 diff --git a/test/pts/sdp.md b/test/pts/sdp.md new file mode 100644 index 000000000..e69de29bb