Skip to content

Commit 4557b2f

Browse files
gzh-terrykartben
authored andcommitted
Bluetooth: AVRCP: add buffer length protections.
Add sanity checks for AVRCP responses received. Signed-off-by: Zihao Gao <[email protected]>
1 parent cb0b472 commit 4557b2f

File tree

1 file changed

+13
-1
lines changed
  • subsys/bluetooth/host/classic

1 file changed

+13
-1
lines changed

subsys/bluetooth/host/classic/avrcp.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ static void avrcp_unit_info_handler(struct bt_avrcp *avrcp, struct net_buf *buf,
259259
} else { /* BT_AVCTP_RESPONSE */
260260
if ((avrcp_cb != NULL) && (avrcp_cb->unit_info_rsp != NULL)) {
261261
net_buf_pull(buf, sizeof(*avrcp_hdr));
262+
if (buf->len != 5) {
263+
LOG_ERR("Invalid unit info length");
264+
return;
265+
}
262266
net_buf_pull_u8(buf); /* Always 0x07 */
263267
rsp.unit_type = FIELD_GET(GENMASK(7, 3), net_buf_pull_u8(buf));
264268
rsp.company_id = net_buf_pull_be24(buf);
@@ -279,6 +283,10 @@ static void avrcp_subunit_info_handler(struct bt_avrcp *avrcp, struct net_buf *b
279283
} else { /* BT_AVCTP_RESPONSE */
280284
if ((avrcp_cb != NULL) && (avrcp_cb->subunit_info_rsp != NULL)) {
281285
net_buf_pull(buf, sizeof(*avrcp_hdr));
286+
if (buf->len < 5) {
287+
LOG_ERR("Invalid subunit info length");
288+
return;
289+
}
282290
net_buf_pull_u8(buf); /* Always 0x07 */
283291
tmp = net_buf_pull_u8(buf);
284292
rsp.subunit_type = FIELD_GET(GENMASK(7, 3), tmp);
@@ -321,8 +329,12 @@ static int avrcp_recv(struct bt_avctp *session, struct net_buf *buf)
321329

322330
avctp_hdr = (void *)buf->data;
323331
net_buf_pull(buf, sizeof(*avctp_hdr));
324-
avrcp_hdr = (void *)buf->data;
332+
if (buf->len < sizeof(*avrcp_hdr)) {
333+
LOG_ERR("invalid AVRCP header received");
334+
return -EINVAL;
335+
}
325336

337+
avrcp_hdr = (void *)buf->data;
326338
tid = BT_AVCTP_HDR_GET_TRANSACTION_LABLE(avctp_hdr);
327339
cr = BT_AVCTP_HDR_GET_CR(avctp_hdr);
328340
ctype = BT_AVRCP_HDR_GET_CTYPE(avrcp_hdr);

0 commit comments

Comments
 (0)