Skip to content

Commit b9ba1e2

Browse files
fix(bt/bluedroid): fixed potential OOB in AVRCP vendor command composition
1 parent 2f63581 commit b9ba1e2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

components/bt/host/bluedroid/stack/avrc/avrc_opt.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,28 @@
4848
******************************************************************************/
4949
static BT_HDR *avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg)
5050
{
51-
BT_HDR *p_cmd;
51+
BT_HDR *p_cmd = NULL;
5252
UINT8 *p_data;
5353

54-
assert(p_msg != NULL);
54+
/*
55+
A vendor dependent command consists of at least of:
56+
- A BT_HDR, plus
57+
- AVCT_MSG_OFFSET, plus
58+
- 3 bytes for ctype, subunit_type and op_vendor, plus
59+
- 3 bytes for company_id
60+
*/
61+
#define AVRC_MIN_VENDOR_CMD_LEN (BT_HDR_SIZE + AVCT_MSG_OFFSET + AVRC_VENDOR_HDR_SIZE)
62+
63+
if (!p_msg) {
64+
return NULL;
65+
}
5566

5667
#if AVRC_METADATA_INCLUDED == TRUE
57-
assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
58-
if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_META_CMD_BUF_SIZE)) != NULL)
68+
if ((AVRC_META_CMD_BUF_SIZE > AVRC_MIN_VENDOR_CMD_LEN + p_msg->vendor_len) &&
69+
((p_cmd = (BT_HDR *) osi_malloc(AVRC_META_CMD_BUF_SIZE)) != NULL))
5970
#else
60-
assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
61-
if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL)
71+
if ((AVRC_CMD_BUF_SIZE > (AVRC_MIN_VENDOR_CMD_LEN + p_msg->vendor_len)) &&
72+
(p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL)
6273
#endif
6374
{
6475
p_cmd->offset = AVCT_MSG_OFFSET;

0 commit comments

Comments
 (0)