Skip to content

Commit d58782f

Browse files
makeshikartben
authored andcommitted
Bluetooth: AVRCP: Return INVALID_COMMAND when PDU ID is invalid
Added a check in the vendor dependent handler to ensure the PDU ID matches supported command handlers. If the PDU ID or command type is invalid, respond with BT_AVRCP_STATUS_INVALID_COMMAND. Signed-off-by: Make Shi <[email protected]>
1 parent de91735 commit d58782f

File tree

1 file changed

+7
-7
lines changed
  • subsys/bluetooth/host/classic

1 file changed

+7
-7
lines changed

subsys/bluetooth/host/classic/avrcp.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,19 +1739,24 @@ static int handle_vendor_pdu(struct bt_avrcp *avrcp, uint8_t tid, struct net_buf
17391739
uint8_t ctype, uint8_t pdu_id,
17401740
const struct avrcp_pdu_vendor_handler *handlers, size_t num_handlers)
17411741
{
1742+
size_t min_len;
1743+
17421744
for (size_t i = 0; i < num_handlers; i++) {
17431745
const struct avrcp_pdu_vendor_handler *handler = &handlers[i];
17441746

17451747
if (handler->pdu_id != pdu_id) {
17461748
continue;
17471749
}
17481750

1751+
if (handlers != rsp_vendor_handlers && ctype != handler->cmd_type) {
1752+
LOG_ERR("Invalid ctype 0x%02x for pdu_id 0x%02x", ctype, pdu_id);
1753+
return BT_AVRCP_STATUS_INVALID_COMMAND;
1754+
}
1755+
17491756
/** For REJECTED responses, only need 1 byte for error code.
17501757
* For NOT_IMPLEMENTED and IN_TRANSITION, no additional data is needed.
17511758
* For other responses, use the handler's minimum length requirement.
17521759
*/
1753-
size_t min_len;
1754-
17551760
if (ctype == BT_AVRCP_RSP_REJECTED) {
17561761
min_len = sizeof(uint8_t);
17571762
} else if (ctype == BT_AVRCP_RSP_NOT_IMPLEMENTED ||
@@ -2383,11 +2388,6 @@ static void avrcp_vendor_dependent_cmd_handler(struct bt_avrcp *avrcp, uint8_t t
23832388
goto err_rsp;
23842389
}
23852390

2386-
if (ctype_or_rsp != get_cmd_type_by_pdu(pdu->pdu_id)) {
2387-
LOG_ERR("Invalid ctype 0x%02x for pdu_id 0x%02x", ctype_or_rsp, pdu->pdu_id);
2388-
error_code = BT_AVRCP_STATUS_INVALID_COMMAND;
2389-
goto err_rsp;
2390-
}
23912391

23922392
error_code = handle_vendor_pdu(avrcp, tid, buf, ctype_or_rsp, pdu->pdu_id,
23932393
cmd_vendor_handlers, ARRAY_SIZE(cmd_vendor_handlers));

0 commit comments

Comments
 (0)