mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
bt: Fixed the problem of out-of-bounds access caused by the variable-length array introduced in 3268075231
Closes https://github.com/espressif/esp-idf/issues/11264
This commit is contained in:
@ -134,6 +134,14 @@ do {
|
|||||||
hf_local_param[idx].btc_hf_cb.num_active = 0; \
|
hf_local_param[idx].btc_hf_cb.num_active = 0; \
|
||||||
hf_local_param[idx].btc_hf_cb.num_held = 0;
|
hf_local_param[idx].btc_hf_cb.num_held = 0;
|
||||||
|
|
||||||
|
#define CHECK_HF_IDX(idx) \
|
||||||
|
do { \
|
||||||
|
if ((idx < 0) || (idx >= BTC_HF_NUM_CB)) { \
|
||||||
|
BTC_TRACE_ERROR("%s: Invalid index %d", __FUNCTION__, idx); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
** Static Function
|
** Static Function
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@ -1213,19 +1221,9 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
tBTA_AG *p_data = (tBTA_AG *)msg->arg;
|
tBTA_AG *p_data = (tBTA_AG *)msg->arg;
|
||||||
esp_hf_cb_param_t param;
|
esp_hf_cb_param_t param;
|
||||||
bdstr_t bdstr;
|
bdstr_t bdstr;
|
||||||
int idx;
|
int idx = BTC_HF_INVALID_IDX;
|
||||||
|
|
||||||
if (p_data == NULL) {
|
|
||||||
idx = BTC_HF_INVALID_IDX;
|
|
||||||
} else {
|
|
||||||
idx = p_data->hdr.handle - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
BTC_TRACE_DEBUG("%s: event = %s", __FUNCTION__, dump_hf_event(event));
|
BTC_TRACE_DEBUG("%s: event = %s", __FUNCTION__, dump_hf_event(event));
|
||||||
if ((idx < 0) || (idx >= BTC_HF_NUM_CB)) {
|
|
||||||
BTC_TRACE_ERROR("%s: Invalid index %d", __FUNCTION__, idx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case BTA_AG_ENABLE_EVT:
|
case BTA_AG_ENABLE_EVT:
|
||||||
@ -1234,6 +1232,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_REGISTER_EVT:
|
case BTA_AG_REGISTER_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
hf_local_param[idx].btc_hf_cb.handle = p_data->reg.hdr.handle;
|
hf_local_param[idx].btc_hf_cb.handle = p_data->reg.hdr.handle;
|
||||||
BTC_TRACE_DEBUG("%s: BTA_AG_REGISTER_EVT," "hf_local_param[%d].btc_hf_cb.handle = %d",
|
BTC_TRACE_DEBUG("%s: BTA_AG_REGISTER_EVT," "hf_local_param[%d].btc_hf_cb.handle = %d",
|
||||||
__FUNCTION__, idx, hf_local_param[idx].btc_hf_cb.handle);
|
__FUNCTION__, idx, hf_local_param[idx].btc_hf_cb.handle);
|
||||||
@ -1242,6 +1242,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_OPEN_EVT:
|
case BTA_AG_OPEN_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
if (p_data->open.status == BTA_AG_SUCCESS)
|
if (p_data->open.status == BTA_AG_SUCCESS)
|
||||||
{
|
{
|
||||||
bdcpy(hf_local_param[idx].btc_hf_cb.connected_bda.address, p_data->open.bd_addr);
|
bdcpy(hf_local_param[idx].btc_hf_cb.connected_bda.address, p_data->open.bd_addr);
|
||||||
@ -1277,6 +1279,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_CONN_EVT:
|
case BTA_AG_CONN_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &(hf_local_param[idx].btc_hf_cb.connected_timestamp));
|
clock_gettime(CLOCK_MONOTONIC, &(hf_local_param[idx].btc_hf_cb.connected_timestamp));
|
||||||
BTC_TRACE_DEBUG("%s: BTA_AG_CONN_EVT, idx = %d ", __FUNCTION__, idx);
|
BTC_TRACE_DEBUG("%s: BTA_AG_CONN_EVT, idx = %d ", __FUNCTION__, idx);
|
||||||
hf_local_param[idx].btc_hf_cb.peer_feat = p_data->conn.peer_feat;
|
hf_local_param[idx].btc_hf_cb.peer_feat = p_data->conn.peer_feat;
|
||||||
@ -1298,6 +1302,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_CLOSE_EVT:
|
case BTA_AG_CLOSE_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
hf_local_param[idx].btc_hf_cb.connected_timestamp.tv_sec = 0;
|
hf_local_param[idx].btc_hf_cb.connected_timestamp.tv_sec = 0;
|
||||||
hf_local_param[idx].btc_hf_cb.connection_state = ESP_HF_CONNECTION_STATE_DISCONNECTED;
|
hf_local_param[idx].btc_hf_cb.connection_state = ESP_HF_CONNECTION_STATE_DISCONNECTED;
|
||||||
BTC_TRACE_DEBUG("%s: BTA_AG_CLOSE_EVT," "hf_local_param[%d].btc_hf_cb.handle = %d", __FUNCTION__,
|
BTC_TRACE_DEBUG("%s: BTA_AG_CLOSE_EVT," "hf_local_param[%d].btc_hf_cb.handle = %d", __FUNCTION__,
|
||||||
@ -1319,6 +1325,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_AUDIO_OPEN_EVT:
|
case BTA_AG_AUDIO_OPEN_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
do {
|
do {
|
||||||
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
||||||
param.audio_stat.state = ESP_HF_AUDIO_STATE_CONNECTED;
|
param.audio_stat.state = ESP_HF_AUDIO_STATE_CONNECTED;
|
||||||
@ -1330,6 +1338,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_AUDIO_MSBC_OPEN_EVT:
|
case BTA_AG_AUDIO_MSBC_OPEN_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
do {
|
do {
|
||||||
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
||||||
param.audio_stat.state = ESP_HF_AUDIO_STATE_CONNECTED_MSBC;
|
param.audio_stat.state = ESP_HF_AUDIO_STATE_CONNECTED_MSBC;
|
||||||
@ -1340,6 +1350,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
}
|
}
|
||||||
case BTA_AG_AUDIO_CLOSE_EVT:
|
case BTA_AG_AUDIO_CLOSE_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
do {
|
do {
|
||||||
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
||||||
param.audio_stat.state = ESP_HF_AUDIO_STATE_DISCONNECTED;
|
param.audio_stat.state = ESP_HF_AUDIO_STATE_DISCONNECTED;
|
||||||
@ -1351,6 +1363,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_AT_BVRA_EVT:
|
case BTA_AG_AT_BVRA_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
do {
|
do {
|
||||||
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
memset(¶m, 0, sizeof(esp_hf_cb_param_t));
|
||||||
param.vra_rep.value = p_data->val.num;
|
param.vra_rep.value = p_data->val.num;
|
||||||
@ -1468,6 +1482,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
case BTA_AG_AT_BINP_EVT:
|
case BTA_AG_AT_BINP_EVT:
|
||||||
case BTA_AG_AT_BTRH_EVT:
|
case BTA_AG_AT_BTRH_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
tBTA_AG_RES_DATA ag_res;
|
tBTA_AG_RES_DATA ag_res;
|
||||||
memset(&ag_res, 0, sizeof(ag_res));
|
memset(&ag_res, 0, sizeof(ag_res));
|
||||||
ag_res.ok_flag = BTA_AG_OK_ERROR;
|
ag_res.ok_flag = BTA_AG_OK_ERROR;
|
||||||
@ -1478,6 +1494,8 @@ void btc_hf_cb_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTA_AG_AT_BAC_EVT:
|
case BTA_AG_AT_BAC_EVT:
|
||||||
{
|
{
|
||||||
|
idx = p_data->hdr.handle - 1;
|
||||||
|
CHECK_HF_IDX(idx);
|
||||||
BTC_TRACE_DEBUG("AG Bitmap of peer-codecs %d", p_data->val.num);
|
BTC_TRACE_DEBUG("AG Bitmap of peer-codecs %d", p_data->val.num);
|
||||||
#if (BTM_WBS_INCLUDED == TRUE)
|
#if (BTM_WBS_INCLUDED == TRUE)
|
||||||
/* If the peer supports mSBC and the BTC prefferred codec is also mSBC, then
|
/* If the peer supports mSBC and the BTC prefferred codec is also mSBC, then
|
||||||
|
Reference in New Issue
Block a user