@@ -115,7 +115,7 @@ struct select_attrs_data {
115
115
uint16_t max_att_len ;
116
116
uint16_t att_list_len ;
117
117
uint8_t cont_state_size ;
118
- uint8_t num_filters ;
118
+ size_t num_filters ;
119
119
bool new_service ;
120
120
};
121
121
@@ -814,7 +814,7 @@ static uint8_t select_attrs(struct bt_sdp_attribute *attr, uint8_t att_idx,
814
814
struct select_attrs_data * sad = user_data ;
815
815
uint16_t att_id_lower , att_id_upper , att_id_cur , space ;
816
816
uint32_t attr_size , seq_size ;
817
- uint8_t idx_filter ;
817
+ size_t idx_filter ;
818
818
819
819
for (idx_filter = 0U ; idx_filter < sad -> num_filters ; idx_filter ++ ) {
820
820
@@ -939,7 +939,7 @@ static uint8_t select_attrs(struct bt_sdp_attribute *attr, uint8_t att_idx,
939
939
* @return len Length of the attribute list created
940
940
*/
941
941
static uint16_t create_attr_list (struct bt_sdp * sdp , struct bt_sdp_record * record ,
942
- uint32_t * filter , uint8_t num_filters ,
942
+ uint32_t * filter , size_t num_filters ,
943
943
uint16_t max_att_len , uint8_t cont_state_size ,
944
944
uint8_t next_att , struct search_state * state ,
945
945
struct net_buf * rsp_buf )
@@ -978,12 +978,13 @@ static uint16_t create_attr_list(struct bt_sdp *sdp, struct bt_sdp_record *recor
978
978
* IDs, the lower 2 bytes contain the ID and the upper 2 bytes are set to
979
979
* 0xFFFF. For attribute ranges, the lower 2bytes indicate the start ID and
980
980
* the upper 2bytes indicate the end ID
981
+ * @param max_filters Max element slots of filter to be filled in
981
982
* @param num_filters No. of filter elements filled in (to be returned)
982
983
*
983
984
* @return 0 for success, or relevant error code
984
985
*/
985
986
static uint16_t get_att_search_list (struct net_buf * buf , uint32_t * filter ,
986
- uint8_t * num_filters )
987
+ size_t max_filters , size_t * num_filters )
987
988
{
988
989
struct bt_sdp_data_elem data_elem ;
989
990
uint16_t res ;
@@ -998,6 +999,11 @@ static uint16_t get_att_search_list(struct net_buf *buf, uint32_t *filter,
998
999
size = data_elem .data_size ;
999
1000
1000
1001
while (size ) {
1002
+ if (* num_filters >= max_filters ) {
1003
+ LOG_WRN ("Exceeded maximum array length %u of %p" , max_filters , filter );
1004
+ return 0 ;
1005
+ }
1006
+
1001
1007
res = parse_data_elem (buf , & data_elem );
1002
1008
if (res ) {
1003
1009
return res ;
@@ -1075,7 +1081,8 @@ static uint16_t sdp_svc_att_req(struct bt_sdp *sdp, struct net_buf *buf,
1075
1081
struct net_buf * rsp_buf ;
1076
1082
uint32_t svc_rec_hdl ;
1077
1083
uint16_t max_att_len , res , att_list_len ;
1078
- uint8_t num_filters , cont_state_size , next_att = 0U ;
1084
+ size_t num_filters ;
1085
+ uint8_t cont_state_size , next_att = 0U ;
1079
1086
1080
1087
if (buf -> len < 6 ) {
1081
1088
LOG_WRN ("Malformed packet" );
@@ -1086,7 +1093,7 @@ static uint16_t sdp_svc_att_req(struct bt_sdp *sdp, struct net_buf *buf,
1086
1093
max_att_len = net_buf_pull_be16 (buf );
1087
1094
1088
1095
/* Set up the filters */
1089
- res = get_att_search_list (buf , filter , & num_filters );
1096
+ res = get_att_search_list (buf , filter , ARRAY_SIZE ( filter ), & num_filters );
1090
1097
if (res ) {
1091
1098
/* Error in parsing */
1092
1099
return res ;
@@ -1191,7 +1198,8 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
1191
1198
struct bt_sdp_att_rsp * rsp ;
1192
1199
struct bt_sdp_data_elem_seq * seq = NULL ;
1193
1200
uint16_t max_att_len , res , att_list_len = 0U ;
1194
- uint8_t num_filters , cont_state_size , next_svc = 0U , next_att = 0U ;
1201
+ size_t num_filters ;
1202
+ uint8_t cont_state_size , next_svc = 0U , next_att = 0U ;
1195
1203
bool dry_run = false;
1196
1204
1197
1205
res = find_services (buf , matching_recs );
@@ -1207,7 +1215,7 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
1207
1215
max_att_len = net_buf_pull_be16 (buf );
1208
1216
1209
1217
/* Set up the filters */
1210
- res = get_att_search_list (buf , filter , & num_filters );
1218
+ res = get_att_search_list (buf , filter , ARRAY_SIZE ( filter ), & num_filters );
1211
1219
1212
1220
if (res ) {
1213
1221
/* Error in parsing */
0 commit comments