@@ -1454,10 +1454,13 @@ static int rfcomm_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
1454
1454
{
1455
1455
struct bt_rfcomm_session * session = RFCOMM_SESSION (chan );
1456
1456
struct bt_rfcomm_hdr * hdr = (void * )buf -> data ;
1457
+ struct bt_rfcomm_hdr_ext * hdr_ext = (void * )buf -> data ;
1457
1458
uint8_t dlci , frame_type , fcs , fcs_len ;
1459
+ uint16_t msg_len ;
1460
+ uint16_t hdr_len ;
1458
1461
1459
1462
/* Need to consider FCS also*/
1460
- if (buf -> len < (sizeof (* hdr ) + 1 )) {
1463
+ if (buf -> len < (sizeof (* hdr ) + sizeof ( fcs ) )) {
1461
1464
LOG_ERR ("Too small RFCOMM Frame" );
1462
1465
return 0 ;
1463
1466
}
@@ -1467,19 +1470,28 @@ static int rfcomm_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
1467
1470
1468
1471
LOG_DBG ("session %p dlci %x type %x" , session , dlci , frame_type );
1469
1472
1470
- fcs_len = (frame_type == BT_RFCOMM_UIH ) ? BT_RFCOMM_FCS_LEN_UIH :
1471
- BT_RFCOMM_FCS_LEN_NON_UIH ;
1472
- fcs = * (net_buf_tail (buf ) - 1 );
1473
+ if (BT_RFCOMM_LEN_EXTENDED (hdr -> length )) {
1474
+ msg_len = BT_RFCOMM_GET_LEN_EXTENDED (hdr_ext -> hdr .length , hdr_ext -> second_length );
1475
+ hdr_len = sizeof (* hdr_ext );
1476
+ } else {
1477
+ msg_len = BT_RFCOMM_GET_LEN (hdr -> length );
1478
+ hdr_len = sizeof (* hdr );
1479
+ }
1480
+
1481
+ if (buf -> len < (hdr_len + msg_len + sizeof (fcs ))) {
1482
+ LOG_ERR ("Too small RFCOMM information (%d < %d)" , buf -> len ,
1483
+ hdr_len + msg_len + sizeof (fcs ));
1484
+ return 0 ;
1485
+ }
1486
+
1487
+ fcs_len = (frame_type == BT_RFCOMM_UIH ) ? BT_RFCOMM_FCS_LEN_UIH : hdr_len ;
1488
+ fcs = * (net_buf_tail (buf ) - sizeof (fcs ));
1473
1489
if (!rfcomm_check_fcs (fcs_len , buf -> data , fcs )) {
1474
1490
LOG_ERR ("FCS check failed" );
1475
1491
return 0 ;
1476
1492
}
1477
1493
1478
- if (BT_RFCOMM_LEN_EXTENDED (hdr -> length )) {
1479
- net_buf_pull (buf , sizeof (* hdr ) + 1 );
1480
- } else {
1481
- net_buf_pull (buf , sizeof (* hdr ));
1482
- }
1494
+ net_buf_pull (buf , hdr_len );
1483
1495
1484
1496
switch (frame_type ) {
1485
1497
case BT_RFCOMM_SABM :
@@ -1489,8 +1501,7 @@ static int rfcomm_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
1489
1501
if (!dlci ) {
1490
1502
rfcomm_handle_msg (session , buf );
1491
1503
} else {
1492
- rfcomm_handle_data (session , buf , dlci ,
1493
- BT_RFCOMM_GET_PF (hdr -> control ));
1504
+ rfcomm_handle_data (session , buf , dlci , BT_RFCOMM_GET_PF (hdr -> control ));
1494
1505
}
1495
1506
break ;
1496
1507
case BT_RFCOMM_DISC :
0 commit comments