@@ -149,22 +149,7 @@ static int net_transmit_status(struct bt_mesh_model *model,
149
149
struct bt_mesh_msg_ctx * ctx ,
150
150
struct net_buf_simple * buf )
151
151
{
152
- uint8_t * status ;
153
-
154
- BT_DBG ("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s" ,
155
- ctx -> net_idx , ctx -> app_idx , ctx -> addr , buf -> len ,
156
- bt_hex (buf -> data , buf -> len ));
157
-
158
- if (!bt_mesh_msg_ack_ctx_match (& cli -> ack_ctx , OP_NET_TRANSMIT_STATUS , ctx -> addr ,
159
- (void * * )& status )) {
160
- return - ENOENT ;
161
- }
162
-
163
- * status = net_buf_simple_pull_u8 (buf );
164
-
165
- bt_mesh_msg_ack_ctx_rx (& cli -> ack_ctx );
166
-
167
- return 0 ;
152
+ return state_status_u8 (model , ctx , buf , OP_NET_TRANSMIT_STATUS );
168
153
}
169
154
170
155
struct net_key_param {
@@ -235,6 +220,11 @@ static int net_key_list(struct bt_mesh_model *model,
235
220
param -> keys [i ++ ] = net_buf_simple_pull_le16 (buf ) & 0xfff ;
236
221
}
237
222
223
+ if (buf -> len > 0 ) {
224
+ BT_ERR ("The message size for the application opcode is incorrect." );
225
+ return - EMSGSIZE ;
226
+ }
227
+
238
228
* param -> key_cnt = i ;
239
229
240
230
bt_mesh_msg_ack_ctx_rx (& cli -> ack_ctx );
@@ -247,11 +237,11 @@ static int node_reset_status(struct bt_mesh_model *model,
247
237
struct net_buf_simple * buf )
248
238
{
249
239
bool * param = NULL ;
250
- BT_DBG ("net_idx 0x%04x app_idx 0x%04x src 0x%04x" ,
251
- ctx -> net_idx , ctx -> app_idx , ctx -> addr );
240
+ BT_DBG ("net_idx 0x%04x app_idx 0x%04x src 0x%04x" , ctx -> net_idx ,
241
+ ctx -> app_idx , ctx -> addr );
252
242
253
- if (!bt_mesh_msg_ack_ctx_match (& cli -> ack_ctx , OP_NODE_RESET_STATUS , ctx -> addr ,
254
- (void * * )& param )) {
243
+ if (!bt_mesh_msg_ack_ctx_match (& cli -> ack_ctx , OP_NODE_RESET_STATUS ,
244
+ ctx -> addr , (void * * )& param )) {
255
245
return - ENOENT ;
256
246
}
257
247
@@ -344,6 +334,11 @@ static int app_key_list(struct bt_mesh_model *model,
344
334
param -> keys [i ++ ] = net_buf_simple_pull_le16 (buf ) & 0xfff ;
345
335
}
346
336
337
+ if (buf -> len > 0U ) {
338
+ BT_ERR ("The message size for the application opcode is incorrect." );
339
+ return - EINVAL ;
340
+ }
341
+
347
342
* param -> key_cnt = i ;
348
343
if (param -> status ) {
349
344
* param -> status = status ;
@@ -374,6 +369,11 @@ static int mod_app_status(struct bt_mesh_model *model,
374
369
ctx -> net_idx , ctx -> app_idx , ctx -> addr , buf -> len ,
375
370
bt_hex (buf -> data , buf -> len ));
376
371
372
+ if ((buf -> len != 7U ) && (buf -> len != 9U )) {
373
+ BT_ERR ("The message size for the application opcode is incorrect." );
374
+ return - EMSGSIZE ;
375
+ }
376
+
377
377
if (!bt_mesh_msg_ack_ctx_match (& cli -> ack_ctx , OP_MOD_APP_STATUS , ctx -> addr ,
378
378
(void * * )& param )) {
379
379
return - ENOENT ;
@@ -424,6 +424,11 @@ static int mod_member_list_handle(struct bt_mesh_msg_ctx *ctx,
424
424
uint8_t status ;
425
425
int i ;
426
426
427
+ if ((vnd && buf -> len < 7U ) || (buf -> len < 5U )) {
428
+ BT_ERR ("The message size for the application opcode is incorrect." );
429
+ return - EMSGSIZE ;
430
+ }
431
+
427
432
status = net_buf_simple_pull_u8 (buf );
428
433
elem_addr = net_buf_simple_pull_le16 (buf );
429
434
if (vnd ) {
@@ -438,9 +443,9 @@ static int mod_member_list_handle(struct bt_mesh_msg_ctx *ctx,
438
443
return - ENOENT ;
439
444
}
440
445
441
- if (buf -> len % 2 ) {
442
- BT_WARN ("Model Member List invalid length" );
443
- return - EINVAL ;
446
+ if (buf -> len % 2U ) {
447
+ BT_ERR ("Model Member List invalid length" );
448
+ return - EMSGSIZE ;
444
449
}
445
450
446
451
for (i = 0 ; i < * param -> member_cnt && buf -> len ; i ++ ) {
@@ -513,6 +518,11 @@ static int mod_pub_status(struct bt_mesh_model *model,
513
518
ctx -> net_idx , ctx -> app_idx , ctx -> addr , buf -> len ,
514
519
bt_hex (buf -> data , buf -> len ));
515
520
521
+ if ((buf -> len != 12U ) && (buf -> len != 14U )) {
522
+ BT_ERR ("The message size for the application opcode is incorrect." );
523
+ return - EINVAL ;
524
+ }
525
+
516
526
if (!bt_mesh_msg_ack_ctx_match (& cli -> ack_ctx , OP_MOD_PUB_STATUS , ctx -> addr ,
517
527
(void * * )& param )) {
518
528
return - ENOENT ;
@@ -590,6 +600,11 @@ static int mod_sub_status(struct bt_mesh_model *model,
590
600
ctx -> net_idx , ctx -> app_idx , ctx -> addr , buf -> len ,
591
601
bt_hex (buf -> data , buf -> len ));
592
602
603
+ if ((buf -> len != 7U ) && (buf -> len != 9U )) {
604
+ BT_ERR ("The message size for the application opcode is incorrect." );
605
+ return - EINVAL ;
606
+ }
607
+
593
608
if (!bt_mesh_msg_ack_ctx_match (& cli -> ack_ctx , OP_MOD_SUB_STATUS , ctx -> addr ,
594
609
(void * * )& param )) {
595
610
return - ENOENT ;
@@ -734,27 +749,27 @@ static int hb_pub_status(struct bt_mesh_model *model,
734
749
}
735
750
736
751
const struct bt_mesh_model_op bt_mesh_cfg_cli_op [] = {
737
- { OP_DEV_COMP_DATA_STATUS , 15 , comp_data_status },
738
- { OP_BEACON_STATUS , 1 , beacon_status },
739
- { OP_DEFAULT_TTL_STATUS , 1 , ttl_status },
740
- { OP_FRIEND_STATUS , 1 , friend_status },
741
- { OP_GATT_PROXY_STATUS , 1 , gatt_proxy_status },
742
- { OP_RELAY_STATUS , 2 , relay_status },
743
- { OP_NET_TRANSMIT_STATUS , 1 , net_transmit_status },
744
- { OP_NET_KEY_STATUS , 3 , net_key_status },
745
- { OP_NET_KEY_LIST , 0 , net_key_list },
746
- { OP_APP_KEY_STATUS , 4 , app_key_status },
747
- { OP_APP_KEY_LIST , 3 , app_key_list },
748
- { OP_MOD_APP_STATUS , 7 , mod_app_status },
749
- { OP_SIG_MOD_APP_LIST , 5 , mod_app_list },
750
- { OP_VND_MOD_APP_LIST , 7 , mod_app_list_vnd },
751
- { OP_MOD_PUB_STATUS , 12 , mod_pub_status },
752
- { OP_MOD_SUB_STATUS , 7 , mod_sub_status },
753
- { OP_MOD_SUB_LIST , 5 , mod_sub_list },
754
- { OP_MOD_SUB_LIST_VND , 7 , mod_sub_list_vnd },
755
- { OP_HEARTBEAT_SUB_STATUS , 9 , hb_sub_status },
756
- { OP_HEARTBEAT_PUB_STATUS , 10 , hb_pub_status },
757
- { OP_NODE_RESET_STATUS , 0 , node_reset_status },
752
+ { OP_DEV_COMP_DATA_STATUS , BT_MESH_LEN_MIN ( 15 ), comp_data_status },
753
+ { OP_BEACON_STATUS , BT_MESH_LEN_EXACT ( 1 ), beacon_status },
754
+ { OP_DEFAULT_TTL_STATUS , BT_MESH_LEN_EXACT ( 1 ), ttl_status },
755
+ { OP_FRIEND_STATUS , BT_MESH_LEN_EXACT ( 1 ), friend_status },
756
+ { OP_GATT_PROXY_STATUS , BT_MESH_LEN_EXACT ( 1 ), gatt_proxy_status },
757
+ { OP_RELAY_STATUS , BT_MESH_LEN_EXACT ( 2 ), relay_status },
758
+ { OP_NET_TRANSMIT_STATUS , BT_MESH_LEN_EXACT ( 1 ), net_transmit_status },
759
+ { OP_NET_KEY_STATUS , BT_MESH_LEN_EXACT ( 3 ), net_key_status },
760
+ { OP_NET_KEY_LIST , BT_MESH_LEN_MIN ( 0 ), net_key_list },
761
+ { OP_APP_KEY_STATUS , BT_MESH_LEN_EXACT ( 4 ), app_key_status },
762
+ { OP_APP_KEY_LIST , BT_MESH_LEN_MIN ( 3 ), app_key_list },
763
+ { OP_MOD_APP_STATUS , BT_MESH_LEN_MIN ( 7 ), mod_app_status },
764
+ { OP_SIG_MOD_APP_LIST , BT_MESH_LEN_MIN ( 5 ), mod_app_list },
765
+ { OP_VND_MOD_APP_LIST , BT_MESH_LEN_MIN ( 7 ), mod_app_list_vnd },
766
+ { OP_MOD_PUB_STATUS , BT_MESH_LEN_MIN ( 12 ), mod_pub_status },
767
+ { OP_MOD_SUB_STATUS , BT_MESH_LEN_MIN ( 7 ), mod_sub_status },
768
+ { OP_MOD_SUB_LIST , BT_MESH_LEN_MIN ( 5 ), mod_sub_list },
769
+ { OP_MOD_SUB_LIST_VND , BT_MESH_LEN_MIN ( 7 ), mod_sub_list_vnd },
770
+ { OP_HEARTBEAT_SUB_STATUS , BT_MESH_LEN_EXACT ( 9 ), hb_sub_status },
771
+ { OP_HEARTBEAT_PUB_STATUS , BT_MESH_LEN_EXACT ( 10 ), hb_pub_status },
772
+ { OP_NODE_RESET_STATUS , BT_MESH_LEN_EXACT ( 0 ), node_reset_status },
758
773
BT_MESH_MODEL_OP_END ,
759
774
};
760
775
0 commit comments