diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc index 4a83cde884281fe749c3f0f85327c9be015f9f9b..d0119ec7e5babee147e04869be1d91befbd04441 100644 --- a/system/stack/btm/btm_sec.cc +++ b/system/stack/btm/btm_sec.cc @@ -2985,13 +2985,23 @@ void btm_rem_oob_req(const uint8_t* p) { * Returns void * ******************************************************************************/ -void btm_read_local_oob_complete(uint8_t* p) { +void btm_read_local_oob_complete(uint8_t* p, uint16_t evt_len) { tBTM_SP_LOC_OOB evt_data; - uint8_t status = *p++; + uint8_t status; + if (evt_len < 1) { + goto err_out; + } + + STREAM_TO_UINT8(status, p); BTM_TRACE_EVENT("btm_read_local_oob_complete:%d", status); if (status == HCI_SUCCESS) { evt_data.status = BTM_SUCCESS; + + if (evt_len < 1 + 32) { + goto err_out; + } + STREAM_TO_ARRAY16(evt_data.c.data(), p); STREAM_TO_ARRAY16(evt_data.r.data(), p); } else @@ -3002,6 +3012,11 @@ void btm_read_local_oob_complete(uint8_t* p) { btm_sp_evt_data.loc_oob = evt_data; (*btm_cb.api.p_sp_callback)(BTM_SP_LOC_OOB_EVT, &btm_sp_evt_data); } + + return; + +err_out: + BTM_TRACE_ERROR("%s malformatted event packet, too short", __func__); } /******************************************************************************* diff --git a/system/stack/btm/btm_sec.h b/system/stack/btm/btm_sec.h index 8b92d5d78cd99eba94e3db8b215032ff17bc0ec0..d6f76fc0e7e660e3c7476b14bc33cb3d031c7fad 100644 --- a/system/stack/btm/btm_sec.h +++ b/system/stack/btm/btm_sec.h @@ -582,7 +582,7 @@ void btm_rem_oob_req(const uint8_t* p); * Returns void * ******************************************************************************/ -void btm_read_local_oob_complete(uint8_t* p); +void btm_read_local_oob_complete(uint8_t* p, uint16_t evt_len); /******************************************************************************* * diff --git a/system/stack/btu/btu_hcif.cc b/system/stack/btu/btu_hcif.cc index b1f1a3951a010bcca0d4703629ec5f9bc1c42150..6582539cd3e201c745e1981fa2bbc7cf0224e61b 100644 --- a/system/stack/btu/btu_hcif.cc +++ b/system/stack/btu/btu_hcif.cc @@ -1220,7 +1220,7 @@ static void btu_hcif_hdl_command_complete(uint16_t opcode, uint8_t* p, break; case HCI_READ_LOCAL_OOB_DATA: - btm_read_local_oob_complete(p); + btm_read_local_oob_complete(p, evt_len); break; case HCI_READ_INQ_TX_POWER_LEVEL: diff --git a/system/stack/include/sec_hci_link_interface.h b/system/stack/include/sec_hci_link_interface.h index b5dda7f407c51ffe7397a1c693e8ed5b2c4a69ae..86725d770e531a6f747920aec0d8b5db6cd5949a 100644 --- a/system/stack/include/sec_hci_link_interface.h +++ b/system/stack/include/sec_hci_link_interface.h @@ -31,7 +31,7 @@ void btm_io_capabilities_req(const RawAddress& p); void btm_io_capabilities_rsp(const uint8_t* p); void btm_proc_sp_req_evt(tBTM_SP_EVT event, const uint8_t* p); void btm_read_inq_tx_power_complete(uint8_t* p); -void btm_read_local_oob_complete(uint8_t* p); +void btm_read_local_oob_complete(uint8_t* p, uint16_t evt_len); void btm_rem_oob_req(const uint8_t* p); void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status); void btm_sec_disconnected(uint16_t handle, tHCI_STATUS reason, std::string); diff --git a/system/test/mock/mock_stack_btm_sec.cc b/system/test/mock/mock_stack_btm_sec.cc index 56a0db187b527264a2ed0739803a107e7148f868..6e6df380ccd47649f62bc137fa3a38dcfa0dcfbc 100644 --- a/system/test/mock/mock_stack_btm_sec.cc +++ b/system/test/mock/mock_stack_btm_sec.cc @@ -251,7 +251,7 @@ void btm_io_capabilities_rsp(const uint8_t* p) { void btm_proc_sp_req_evt(tBTM_SP_EVT event, const uint8_t* p) { mock_function_count_map[__func__]++; } -void btm_read_local_oob_complete(uint8_t* p) { +void btm_read_local_oob_complete(uint8_t* p, uint16_t evt_len) { mock_function_count_map[__func__]++; } void btm_rem_oob_req(const uint8_t* p) { mock_function_count_map[__func__]++; }