Skip to content

Commit

Permalink
Bluetooth: L2CAP: Fix missing buffer length check for sdu_len
Browse files Browse the repository at this point in the history
We should verify that the buffer has sufficient data before attempting
to parse the SDU length field. If we get a too short packet just
disconnect the channel.

Fixes #32497

Signed-off-by: Johan Hedberg <[email protected]>
  • Loading branch information
Johan Hedberg authored and jhedberg committed Feb 24, 2021
1 parent e8224c3 commit 0ba9437
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions subsys/bluetooth/host/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,12 @@ static void l2cap_chan_le_recv(struct bt_l2cap_le_chan *chan,
return;
}

if (buf->len < 2) {
BT_WARN("Too short data packet");
bt_l2cap_chan_disconnect(&chan->chan);
return;
}

sdu_len = net_buf_pull_le16(buf);

BT_DBG("chan %p len %u sdu_len %u", chan, buf->len, sdu_len);
Expand Down

0 comments on commit 0ba9437

Please sign in to comment.