Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion btif/src/bluetooth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,14 @@ static int get_connection_state(const RawAddress* bd_addr) {

static int pin_reply(const RawAddress* bd_addr, uint8_t accept, uint8_t pin_len,
bt_pin_code_t* pin_code) {
bt_pin_code_t tmp_pin_code;
/* sanity check */
if (!interface_ready()) return BT_STATUS_NOT_READY;
if (pin_code == nullptr || pin_len > PIN_CODE_LEN) return BT_STATUS_FAIL;

memcpy(&tmp_pin_code, pin_code, pin_len);
do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_pin_reply, *bd_addr,
accept, pin_len, *pin_code));
accept, pin_len, tmp_pin_code));
return BT_STATUS_SUCCESS;
}

Expand Down
15 changes: 13 additions & 2 deletions stack/avct/avct_lcb_act.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ static BT_HDR* avct_lcb_msg_asmbl(tAVCT_LCB* p_lcb, BT_HDR* p_buf) {
pkt_type = AVCT_PKT_TYPE(p);

/* quick sanity check on length */
if (p_buf->len < avct_lcb_pkt_type_len[pkt_type]) {
if (p_buf->len < avct_lcb_pkt_type_len[pkt_type] ||
(sizeof(BT_HDR) + p_buf->offset + p_buf->len) > BT_DEFAULT_BUFFER_SIZE) {
if ((sizeof(BT_HDR) + p_buf->offset + p_buf->len) >
BT_DEFAULT_BUFFER_SIZE) {
android_errorWriteWithInfoLog(0x534e4554, "230867224", -1, NULL, 0);
}
osi_free(p_buf);
AVCT_TRACE_WARNING("Bad length during reassembly");
p_ret = NULL;
Expand All @@ -88,13 +93,19 @@ static BT_HDR* avct_lcb_msg_asmbl(tAVCT_LCB* p_lcb, BT_HDR* p_buf) {
if (p_lcb->p_rx_msg != NULL)
AVCT_TRACE_WARNING("Got start during reassembly");

osi_free(p_lcb->p_rx_msg);
osi_free_and_reset((void**)&p_lcb->p_rx_msg);

/*
* Allocate bigger buffer for reassembly. As lower layers are
* not aware of possible packet size after reassembly, they
* would have allocated smaller buffer.
*/
if (sizeof(BT_HDR) + p_buf->offset + p_buf->len > BT_DEFAULT_BUFFER_SIZE) {
android_errorWriteLog(0x534e4554, "232023771");
osi_free(p_buf);
p_ret = NULL;
return p_ret;
}
p_lcb->p_rx_msg = (BT_HDR*)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
memcpy(p_lcb->p_rx_msg, p_buf, sizeof(BT_HDR) + p_buf->offset + p_buf->len);

Expand Down
6 changes: 6 additions & 0 deletions stack/avdt/avdt_msg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,12 @@ BT_HDR* avdt_msg_asmbl(AvdtpCcb* p_ccb, BT_HDR* p_buf) {
* not aware of possible packet size after reassembly, they
* would have allocated smaller buffer.
*/
if (sizeof(BT_HDR) + p_buf->offset + p_buf->len > BT_DEFAULT_BUFFER_SIZE) {
android_errorWriteLog(0x534e4554, "232023771");
osi_free(p_buf);
p_ret = NULL;
return p_ret;
}
p_ccb->p_rx_msg = (BT_HDR*)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
memcpy(p_ccb->p_rx_msg, p_buf, sizeof(BT_HDR) + p_buf->offset + p_buf->len);

Expand Down
2 changes: 1 addition & 1 deletion stack/avdt/avdt_scb_act.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ uint8_t* avdt_scb_hdl_report(AvdtpScb* p_scb, uint8_t* p, uint16_t len) {
uint8_t* p_start = p;
uint32_t ssrc;
uint8_t o_v, o_p, o_cc;
uint16_t min_len = 0;
uint32_t min_len = 0;
AVDT_REPORT_TYPE pt;
tAVDT_REPORT_DATA report;

Expand Down
39 changes: 11 additions & 28 deletions stack/avrc/avrc_pars_ct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR* p_msg,

tAVRC_STS avrc_parse_notification_rsp(uint8_t* p_stream, uint16_t len,
tAVRC_REG_NOTIF_RSP* p_rsp) {
uint16_t min_len = 1;
uint32_t min_len = 1;

if (len < min_len) goto length_error;
BE_STREAM_TO_UINT8(p_rsp->event_id, p_stream);
Expand Down Expand Up @@ -237,7 +237,7 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg,
}
BE_STREAM_TO_UINT8(pdu, p);
uint16_t pkt_len;
uint16_t min_len = 0;
uint32_t min_len = 0;
/* read the entire packet len */
BE_STREAM_TO_UINT16(pkt_len, p);

Expand Down Expand Up @@ -279,7 +279,7 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg,
get_item_rsp->uid_counter, get_item_rsp->item_count);

/* get each of the items */
get_item_rsp->p_item_list = (tAVRC_ITEM*)osi_malloc(
get_item_rsp->p_item_list = (tAVRC_ITEM*)osi_calloc(
get_item_rsp->item_count * (sizeof(tAVRC_ITEM)));
tAVRC_ITEM* curr_item = get_item_rsp->p_item_list;
for (int i = 0; i < get_item_rsp->item_count; i++) {
Expand Down Expand Up @@ -369,7 +369,7 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg,
__func__, media->type, media->name.charset_id,
media->name.str_len, media->attr_count);

media->p_attr_list = (tAVRC_ATTR_ENTRY*)osi_malloc(
media->p_attr_list = (tAVRC_ATTR_ENTRY*)osi_calloc(
media->attr_count * sizeof(tAVRC_ATTR_ENTRY));
for (int jk = 0; jk < media->attr_count; jk++) {
tAVRC_ATTR_ENTRY* attr_entry = &(media->p_attr_list[jk]);
Expand All @@ -380,14 +380,8 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg,
/* Parse the name now */
BE_STREAM_TO_UINT16(attr_entry->name.charset_id, p);
BE_STREAM_TO_UINT16(attr_entry->name.str_len, p);
if (static_cast<uint16_t>(min_len + attr_entry->name.str_len) <
min_len) {
// Check for overflow
android_errorWriteLog(0x534e4554, "205570663");
}
if (pkt_len - min_len < attr_entry->name.str_len)
goto browse_length_error;
min_len += attr_entry->name.str_len;
if (pkt_len < min_len) goto browse_length_error;
attr_entry->name.p_str = (uint8_t*)osi_malloc(
attr_entry->name.str_len * sizeof(uint8_t));
BE_STREAM_TO_ARRAY(p, attr_entry->name.p_str,
Expand Down Expand Up @@ -441,7 +435,7 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg,
}
BE_STREAM_TO_UINT8(get_attr_rsp->status, p)
BE_STREAM_TO_UINT8(get_attr_rsp->num_attrs, p);
get_attr_rsp->p_attrs = (tAVRC_ATTR_ENTRY*)osi_malloc(
get_attr_rsp->p_attrs = (tAVRC_ATTR_ENTRY*)osi_calloc(
get_attr_rsp->num_attrs * sizeof(tAVRC_ATTR_ENTRY));
for (int i = 0; i < get_attr_rsp->num_attrs; i++) {
tAVRC_ATTR_ENTRY* attr_entry = &(get_attr_rsp->p_attrs[i]);
Expand All @@ -450,14 +444,8 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg,
BE_STREAM_TO_UINT32(attr_entry->attr_id, p);
BE_STREAM_TO_UINT16(attr_entry->name.charset_id, p);
BE_STREAM_TO_UINT16(attr_entry->name.str_len, p);
if (static_cast<uint16_t>(min_len + attr_entry->name.str_len) <
min_len) {
// Check for overflow
android_errorWriteLog(0x534e4554, "205570663");
}
if (pkt_len - min_len < attr_entry->name.str_len)
goto browse_length_error;
min_len += attr_entry->name.str_len;
if (pkt_len < min_len) goto browse_length_error;
attr_entry->name.p_str =
(uint8_t*)osi_malloc(attr_entry->name.str_len * sizeof(uint8_t));
BE_STREAM_TO_ARRAY(p, attr_entry->name.p_str, attr_entry->name.str_len);
Expand Down Expand Up @@ -493,7 +481,7 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg,
__func__, set_br_pl_rsp->status, set_br_pl_rsp->num_items,
set_br_pl_rsp->charset_id, set_br_pl_rsp->folder_depth);

set_br_pl_rsp->p_folders = (tAVRC_NAME*)osi_malloc(
set_br_pl_rsp->p_folders = (tAVRC_NAME*)osi_calloc(
set_br_pl_rsp->folder_depth * sizeof(tAVRC_NAME));

/* Read each of the folder in the depth */
Expand Down Expand Up @@ -553,7 +541,7 @@ static tAVRC_STS avrc_ctrl_pars_vendor_rsp(tAVRC_MSG_VENDOR* p_msg,
p++; /* skip the reserved/packe_type byte */

uint16_t len;
uint16_t min_len = 0;
uint32_t min_len = 0;
BE_STREAM_TO_UINT16(len, p);
AVRC_TRACE_DEBUG("%s ctype:0x%x pdu:0x%x, len:%d vendor_len=0x%x", __func__,
p_msg->hdr.ctype, p_result->pdu, len, p_msg->vendor_len);
Expand Down Expand Up @@ -827,20 +815,15 @@ static tAVRC_STS avrc_ctrl_pars_vendor_rsp(tAVRC_MSG_VENDOR* p_msg,
BE_STREAM_TO_UINT32(p_attrs[i].attr_id, p);
BE_STREAM_TO_UINT16(p_attrs[i].name.charset_id, p);
BE_STREAM_TO_UINT16(p_attrs[i].name.str_len, p);
if (static_cast<uint16_t>(min_len + p_attrs[i].name.str_len) <
min_len) {
// Check for overflow
android_errorWriteLog(0x534e4554, "205570663");
}
if (len - min_len < p_attrs[i].name.str_len) {
min_len += p_attrs[i].name.str_len;
if (len < min_len) {
for (int j = 0; j < i; j++) {
osi_free(p_attrs[j].name.p_str);
}
osi_free(p_attrs);
p_result->get_attrs.num_attrs = 0;
goto length_error;
}
min_len += p_attrs[i].name.str_len;
if (p_attrs[i].name.str_len > 0) {
p_attrs[i].name.p_str =
(uint8_t*)osi_calloc(p_attrs[i].name.str_len);
Expand Down
2 changes: 1 addition & 1 deletion stack/avrc/avrc_pars_tg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ static tAVRC_STS avrc_pars_browsing_cmd(tAVRC_MSG_BROWSE* p_msg,
uint8_t* p = p_msg->p_browse_data;
int count;

uint16_t min_len = 3;
uint32_t min_len = 3;
RETURN_STATUS_IF_FALSE(AVRC_STS_BAD_CMD, (p_msg->browse_len >= min_len),
"msg too short");

Expand Down
1 change: 1 addition & 0 deletions stack/bnep/bnep_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ tBNEP_RESULT BNEP_ConnectResp(uint16_t handle, tBNEP_RESULT resp) {
p = (uint8_t*)(p_bcb->p_pending_data + 1) + p_bcb->p_pending_data->offset;
while (extension_present && p && rem_len) {
ext_type = *p++;
rem_len--;
extension_present = ext_type >> 7;
ext_type &= 0x7F;

Expand Down
2 changes: 1 addition & 1 deletion stack/sdp/sdp_discovery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void process_service_search_rsp(tCONN_CB* p_ccb, uint8_t* p_reply,

orig = p_ccb->num_handles;
p_ccb->num_handles += cur_handles;
if (p_ccb->num_handles == 0) {
if (p_ccb->num_handles == 0 || p_ccb->num_handles < orig) {
SDP_TRACE_WARNING("SDP - Rcvd ServiceSearchRsp, no matches");
sdp_disconnect(p_ccb, SDP_NO_RECS_MATCH);
return;
Expand Down