Skip to content

Commit a0c8a43

Browse files
ekleezgMaureenHelm
authored andcommitted
Bluetooth: Classic: Add length check in bluetooth classic
Added length checks for user input in `sdp_client_receive` and `l2cap_br_info_rsp`. Signed-off-by: Eunkyu Lee <[email protected]> (cherry picked from commit 8888125)
1 parent ecfc6e1 commit a0c8a43

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

subsys/bluetooth/host/l2cap_br.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
392392

393393
switch (type) {
394394
case BT_L2CAP_INFO_FEAT_MASK:
395+
if (buf->len < sizeof(uint32_t)) {
396+
LOG_ERR("Invalid remote info feat mask");
397+
err = -EINVAL;
398+
break;
399+
}
395400
l2cap->info_feat_mask = net_buf_pull_le32(buf);
396401
LOG_DBG("remote info mask 0x%08x", l2cap->info_feat_mask);
397402

@@ -402,6 +407,11 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
402407
l2cap_br_get_info(l2cap, BT_L2CAP_INFO_FIXED_CHAN);
403408
return 0;
404409
case BT_L2CAP_INFO_FIXED_CHAN:
410+
if (buf->len < sizeof(uint8_t)) {
411+
LOG_ERR("Invalid remote info fixed chan");
412+
err = -EINVAL;
413+
break;
414+
}
405415
l2cap->info_fixed_chan = net_buf_pull_u8(buf);
406416
LOG_DBG("remote fixed channel mask 0x%02x", l2cap->info_fixed_chan);
407417

subsys/bluetooth/host/sdp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,11 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
17501750

17511751
switch (hdr->op_code) {
17521752
case BT_SDP_SVC_SEARCH_ATTR_RSP:
1753+
/* Check the buffer len for the length field */
1754+
if (buf->len < sizeof(uint16_t)) {
1755+
LOG_ERR("Invalid frame payload length");
1756+
return 0;
1757+
}
17531758
/* Get number of attributes in this frame. */
17541759
frame_len = net_buf_pull_be16(buf);
17551760
/* Check valid buf len for attribute list and cont state */

0 commit comments

Comments
 (0)