system/bt
Revision | ae9562805e14540bdd41c271c5248e751d8c4b9c (tree) |
---|---|
Time | 2019-01-08 17:16:56 |
Author | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge tag 'android-8.1.0_r60' into oreo-x86
Android 8.1.0 Release 60 (OPM8.190105.002)
@@ -58,7 +58,7 @@ const tBTA_SERVICE_MASK bta_ag_svc_mask[BTA_AG_NUM_IDX] = { | ||
58 | 58 | BTA_HSP_SERVICE_MASK, BTA_HFP_SERVICE_MASK}; |
59 | 59 | |
60 | 60 | typedef void (*tBTA_AG_ATCMD_CBACK)(tBTA_AG_SCB* p_scb, uint16_t cmd, |
61 | - uint8_t arg_type, char* p_arg, | |
61 | + uint8_t arg_type, char* p_arg, char* p_end, | |
62 | 62 | int16_t int_arg); |
63 | 63 | |
64 | 64 | const tBTA_AG_ATCMD_CBACK bta_ag_at_cback_tbl[BTA_AG_NUM_IDX] = { |
@@ -26,6 +26,7 @@ | ||
26 | 26 | |
27 | 27 | #include "bt_common.h" |
28 | 28 | #include "bta_ag_at.h" |
29 | +#include "log/log.h" | |
29 | 30 | #include "utl.h" |
30 | 31 | |
31 | 32 | /***************************************************************************** |
@@ -76,7 +77,7 @@ void bta_ag_at_reinit(tBTA_AG_AT_CB* p_cb) { | ||
76 | 77 | * Returns void |
77 | 78 | * |
78 | 79 | *****************************************************************************/ |
79 | -void bta_ag_process_at(tBTA_AG_AT_CB* p_cb) { | |
80 | +void bta_ag_process_at(tBTA_AG_AT_CB* p_cb, char* p_end) { | |
80 | 81 | uint16_t idx; |
81 | 82 | uint8_t arg_type; |
82 | 83 | char* p_arg; |
@@ -92,6 +93,11 @@ void bta_ag_process_at(tBTA_AG_AT_CB* p_cb) { | ||
92 | 93 | if (p_cb->p_at_tbl[idx].p_cmd[0] != 0) { |
93 | 94 | /* start of argument is p + strlen matching command */ |
94 | 95 | p_arg = p_cb->p_cmd_buf + strlen(p_cb->p_at_tbl[idx].p_cmd); |
96 | + if (p_arg > p_end) { | |
97 | + (*p_cb->p_err_cback)(p_cb->p_user, false, NULL); | |
98 | + android_errorWriteLog(0x534e4554, "112860487"); | |
99 | + return; | |
100 | + } | |
95 | 101 | |
96 | 102 | /* if no argument */ |
97 | 103 | if (p_arg[0] == 0) { |
@@ -132,11 +138,11 @@ void bta_ag_process_at(tBTA_AG_AT_CB* p_cb) { | ||
132 | 138 | (*p_cb->p_err_cback)(p_cb->p_user, false, NULL); |
133 | 139 | } else { |
134 | 140 | (*p_cb->p_cmd_cback)(p_cb->p_user, p_cb->p_at_tbl[idx].command_id, |
135 | - arg_type, p_arg, int_arg); | |
141 | + arg_type, p_arg, p_end, int_arg); | |
136 | 142 | } |
137 | 143 | } else { |
138 | 144 | (*p_cb->p_cmd_cback)(p_cb->p_user, p_cb->p_at_tbl[idx].command_id, |
139 | - arg_type, p_arg, int_arg); | |
145 | + arg_type, p_arg, p_end, int_arg); | |
140 | 146 | } |
141 | 147 | } |
142 | 148 | /* else error */ |
@@ -187,8 +193,9 @@ void bta_ag_at_parse(tBTA_AG_AT_CB* p_cb, char* p_buf, uint16_t len) { | ||
187 | 193 | (p_cb->p_cmd_buf[0] == 'A' || p_cb->p_cmd_buf[0] == 'a') && |
188 | 194 | (p_cb->p_cmd_buf[1] == 'T' || p_cb->p_cmd_buf[1] == 't')) { |
189 | 195 | p_save = p_cb->p_cmd_buf; |
196 | + char* p_end = p_cb->p_cmd_buf + p_cb->cmd_pos; | |
190 | 197 | p_cb->p_cmd_buf += 2; |
191 | - bta_ag_process_at(p_cb); | |
198 | + bta_ag_process_at(p_cb, p_end); | |
192 | 199 | p_cb->p_cmd_buf = p_save; |
193 | 200 | } |
194 | 201 |
@@ -55,7 +55,7 @@ typedef struct { | ||
55 | 55 | |
56 | 56 | /* callback function executed when command is parsed */ |
57 | 57 | typedef void(tBTA_AG_AT_CMD_CBACK)(void* p_user, uint16_t command_id, |
58 | - uint8_t arg_type, char* p_arg, | |
58 | + uint8_t arg_type, char* p_arg, char* p_end, | |
59 | 59 | int16_t int_arg); |
60 | 60 | |
61 | 61 | /* callback function executed to send "ERROR" result code */ |
@@ -30,6 +30,7 @@ | ||
30 | 30 | #include "bta_ag_int.h" |
31 | 31 | #include "bta_api.h" |
32 | 32 | #include "bta_sys.h" |
33 | +#include "log/log.h" | |
33 | 34 | #include "osi/include/log.h" |
34 | 35 | #include "osi/include/osi.h" |
35 | 36 | #include "port_api.h" |
@@ -378,23 +379,23 @@ static void bta_ag_send_ind(tBTA_AG_SCB* p_scb, uint16_t id, uint16_t value, | ||
378 | 379 | * Returns true if parsed ok, false otherwise. |
379 | 380 | * |
380 | 381 | ******************************************************************************/ |
381 | -static bool bta_ag_parse_cmer(char* p_s, bool* p_enabled) { | |
382 | +static bool bta_ag_parse_cmer(char* p_s, char* p_end, bool* p_enabled) { | |
382 | 383 | int16_t n[4] = {-1, -1, -1, -1}; |
383 | 384 | int i; |
384 | 385 | char* p; |
385 | 386 | |
386 | - for (i = 0; i < 4; i++) { | |
387 | + for (i = 0; i < 4; i++, p_s = p + 1) { | |
387 | 388 | /* skip to comma delimiter */ |
388 | - for (p = p_s; *p != ',' && *p != 0; p++) | |
389 | + for (p = p_s; p < p_end && *p != ',' && *p != 0; p++) | |
389 | 390 | ; |
390 | 391 | |
391 | 392 | /* get integer value */ |
393 | + if (p > p_end) { | |
394 | + android_errorWriteLog(0x534e4554, "112860487"); | |
395 | + return false; | |
396 | + } | |
392 | 397 | *p = 0; |
393 | 398 | n[i] = utl_str2int(p_s); |
394 | - p_s = p + 1; | |
395 | - if (p_s == 0) { | |
396 | - break; | |
397 | - } | |
398 | 399 | } |
399 | 400 | |
400 | 401 | /* process values */ |
@@ -452,7 +453,8 @@ static uint8_t bta_ag_parse_chld(UNUSED_ATTR tBTA_AG_SCB* p_scb, char* p_s) { | ||
452 | 453 | * Returns Returns bitmap of supported codecs. |
453 | 454 | * |
454 | 455 | ******************************************************************************/ |
455 | -static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB* p_scb, char* p_s) { | |
456 | +static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB* p_scb, char* p_s, | |
457 | + char* p_end) { | |
456 | 458 | tBTA_AG_PEER_CODEC retval = BTA_AG_CODEC_NONE; |
457 | 459 | uint16_t uuid_codec; |
458 | 460 | bool cont = false; /* Continue processing */ |
@@ -460,10 +462,14 @@ static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB* p_scb, char* p_s) { | ||
460 | 462 | |
461 | 463 | while (p_s) { |
462 | 464 | /* skip to comma delimiter */ |
463 | - for (p = p_s; *p != ',' && *p != 0; p++) | |
465 | + for (p = p_s; p < p_end && *p != ',' && *p != 0; p++) | |
464 | 466 | ; |
465 | 467 | |
466 | 468 | /* get integre value */ |
469 | + if (p > p_end) { | |
470 | + android_errorWriteLog(0x534e4554, "112860487"); | |
471 | + break; | |
472 | + } | |
467 | 473 | if (*p != 0) { |
468 | 474 | *p = 0; |
469 | 475 | cont = true; |
@@ -597,7 +603,8 @@ void bta_ag_send_call_inds(tBTA_AG_SCB* p_scb, tBTA_AG_RES result) { | ||
597 | 603 | * |
598 | 604 | ******************************************************************************/ |
599 | 605 | void bta_ag_at_hsp_cback(tBTA_AG_SCB* p_scb, uint16_t command_id, |
600 | - uint8_t arg_type, char* p_arg, int16_t int_arg) { | |
606 | + uint8_t arg_type, char* p_arg, char* p_end, | |
607 | + int16_t int_arg) { | |
601 | 608 | APPL_TRACE_DEBUG("AT cmd:%d arg_type:%d arg:%d arg:%s", command_id, arg_type, |
602 | 609 | int_arg, p_arg); |
603 | 610 |
@@ -607,6 +614,13 @@ void bta_ag_at_hsp_cback(tBTA_AG_SCB* p_scb, uint16_t command_id, | ||
607 | 614 | val.hdr.handle = bta_ag_scb_to_idx(p_scb); |
608 | 615 | val.hdr.app_id = p_scb->app_id; |
609 | 616 | val.num = (uint16_t)int_arg; |
617 | + | |
618 | + if ((p_end - p_arg + 1) >= (long)sizeof(val.str)) { | |
619 | + APPL_TRACE_ERROR("%s: p_arg is too long, send error and return", __func__); | |
620 | + bta_ag_send_error(p_scb, BTA_AG_ERR_TEXT_TOO_LONG); | |
621 | + android_errorWriteLog(0x534e4554, "112860487"); | |
622 | + return; | |
623 | + } | |
610 | 624 | strlcpy(val.str, p_arg, sizeof(val.str)); |
611 | 625 | |
612 | 626 | /* call callback with event */ |
@@ -836,7 +850,7 @@ static bool bta_ag_parse_biev_response(tBTA_AG_SCB* p_scb, tBTA_AG_VAL* val) { | ||
836 | 850 | * |
837 | 851 | ******************************************************************************/ |
838 | 852 | void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type, |
839 | - char* p_arg, int16_t int_arg) { | |
853 | + char* p_arg, char* p_end, int16_t int_arg) { | |
840 | 854 | tBTA_AG_VAL val; |
841 | 855 | tBTA_AG_SCB* ag_scb; |
842 | 856 | uint32_t i, ind_id; |
@@ -856,6 +870,13 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type, | ||
856 | 870 | val.hdr.status = BTA_AG_SUCCESS; |
857 | 871 | val.num = int_arg; |
858 | 872 | val.bd_addr = p_scb->peer_addr; |
873 | + | |
874 | + if ((p_end - p_arg + 1) >= (long)sizeof(val.str)) { | |
875 | + APPL_TRACE_ERROR("%s: p_arg is too long, send error and return", __func__); | |
876 | + bta_ag_send_error(p_scb, BTA_AG_ERR_TEXT_TOO_LONG); | |
877 | + android_errorWriteLog(0x534e4554, "112860487"); | |
878 | + return; | |
879 | + } | |
859 | 880 | strlcpy(val.str, p_arg, sizeof(val.str)); |
860 | 881 | |
861 | 882 | /** |
@@ -1034,7 +1055,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type, | ||
1034 | 1055 | |
1035 | 1056 | case BTA_AG_LOCAL_EVT_CMER: |
1036 | 1057 | /* if parsed ok store setting, send OK */ |
1037 | - if (bta_ag_parse_cmer(p_arg, &p_scb->cmer_enabled)) { | |
1058 | + if (bta_ag_parse_cmer(p_arg, p_end, &p_scb->cmer_enabled)) { | |
1038 | 1059 | bta_ag_send_ok(p_scb); |
1039 | 1060 | |
1040 | 1061 | /* if service level conn. not already open and our features and |
@@ -1195,7 +1216,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type, | ||
1195 | 1216 | /* store available codecs from the peer */ |
1196 | 1217 | if ((p_scb->peer_features & BTA_AG_PEER_FEAT_CODEC) && |
1197 | 1218 | (p_scb->features & BTA_AG_FEAT_CODEC)) { |
1198 | - p_scb->peer_codecs = bta_ag_parse_bac(p_scb, p_arg); | |
1219 | + p_scb->peer_codecs = bta_ag_parse_bac(p_scb, p_arg, p_end); | |
1199 | 1220 | p_scb->codec_updated = true; |
1200 | 1221 | |
1201 | 1222 | if (p_scb->peer_codecs & BTA_AG_CODEC_MSBC) { |
@@ -361,9 +361,11 @@ extern void bta_ag_sco_conn_rsp(tBTA_AG_SCB* p_scb, | ||
361 | 361 | |
362 | 362 | /* AT command functions */ |
363 | 363 | extern void bta_ag_at_hsp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, |
364 | - uint8_t arg_type, char* p_arg, int16_t int_arg); | |
364 | + uint8_t arg_type, char* p_arg, char* p_end, | |
365 | + int16_t int_arg); | |
365 | 366 | extern void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, |
366 | - uint8_t arg_type, char* p_arg, int16_t int_arg); | |
367 | + uint8_t arg_type, char* p_arg, char* p_end, | |
368 | + int16_t int_arg); | |
367 | 369 | extern void bta_ag_at_err_cback(tBTA_AG_SCB* p_scb, bool unknown, char* p_arg); |
368 | 370 | extern bool bta_ag_inband_enabled(tBTA_AG_SCB* p_scb); |
369 | 371 | extern void bta_ag_send_call_inds(tBTA_AG_SCB* p_scb, tBTA_AG_RES result); |
@@ -26,6 +26,7 @@ | ||
26 | 26 | |
27 | 27 | #if (BTA_HH_INCLUDED == TRUE) |
28 | 28 | |
29 | +#include <log/log.h> | |
29 | 30 | #include <string.h> |
30 | 31 | |
31 | 32 | #include "bta_hh_co.h" |
@@ -701,6 +702,12 @@ void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) { | ||
701 | 702 | APPL_TRACE_DEBUG("Ctrl DATA received w4: event[%s]", |
702 | 703 | bta_hh_get_w4_event(p_cb->w4_evt)); |
703 | 704 | #endif |
705 | + if (pdata->len == 0) { | |
706 | + android_errorWriteLog(0x534e4554, "116108738"); | |
707 | + p_cb->w4_evt = 0; | |
708 | + osi_free_and_reset((void**)&pdata); | |
709 | + return; | |
710 | + } | |
704 | 711 | hs_data.status = BTA_HH_OK; |
705 | 712 | hs_data.handle = p_cb->hid_handle; |
706 | 713 |
@@ -23,6 +23,7 @@ | ||
23 | 23 | * |
24 | 24 | ******************************************************************************/ |
25 | 25 | |
26 | +#include <cutils/log.h> | |
26 | 27 | #include <string.h> |
27 | 28 | #include "a2dp_codec_api.h" |
28 | 29 | #include "avdt_api.h" |
@@ -231,10 +232,14 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { | ||
231 | 232 | uint16_t offset; |
232 | 233 | uint16_t ex_len; |
233 | 234 | uint8_t pad_len = 0; |
235 | + uint16_t len = p_data->p_pkt->len; | |
234 | 236 | |
235 | 237 | p = p_start = (uint8_t*)(p_data->p_pkt + 1) + p_data->p_pkt->offset; |
236 | 238 | |
237 | 239 | /* parse media packet header */ |
240 | + offset = 12; | |
241 | + // AVDT_MSG_PRS_OCTET1(1) + AVDT_MSG_PRS_M_PT(1) + UINT16(2) + UINT32(4) + 4 | |
242 | + if (offset > len) goto length_error; | |
238 | 243 | AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc); |
239 | 244 | AVDT_MSG_PRS_M_PT(p, m_pt, marker); |
240 | 245 | BE_STREAM_TO_UINT16(seq, p); |
@@ -242,18 +247,19 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { | ||
242 | 247 | p += 4; |
243 | 248 | |
244 | 249 | /* skip over any csrc's in packet */ |
250 | + offset += o_cc * 4; | |
245 | 251 | p += o_cc * 4; |
246 | 252 | |
247 | 253 | /* check for and skip over extension header */ |
248 | 254 | if (o_x) { |
255 | + offset += 4; | |
256 | + if (offset > len) goto length_error; | |
249 | 257 | p += 2; |
250 | 258 | BE_STREAM_TO_UINT16(ex_len, p); |
259 | + offset += ex_len * 4; | |
251 | 260 | p += ex_len * 4; |
252 | 261 | } |
253 | 262 | |
254 | - /* save our new offset */ | |
255 | - offset = (uint16_t)(p - p_start); | |
256 | - | |
257 | 263 | /* adjust length for any padding at end of packet */ |
258 | 264 | if (o_p) { |
259 | 265 | /* padding length in last byte of packet */ |
@@ -281,6 +287,12 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { | ||
281 | 287 | osi_free_and_reset((void**)&p_data->p_pkt); |
282 | 288 | } |
283 | 289 | } |
290 | + return; | |
291 | +length_error: | |
292 | + android_errorWriteLog(0x534e4554, "111450156"); | |
293 | + AVDT_TRACE_WARNING("%s: hdl packet length %d too short: must be at least %d", | |
294 | + __func__, len, offset); | |
295 | + osi_free_and_reset((void**)&p_data->p_pkt); | |
284 | 296 | } |
285 | 297 | |
286 | 298 | #if (AVDT_REPORTING == TRUE) |
@@ -298,12 +310,21 @@ uint8_t* avdt_scb_hdl_report(tAVDT_SCB* p_scb, uint8_t* p, uint16_t len) { | ||
298 | 310 | uint8_t* p_start = p; |
299 | 311 | uint32_t ssrc; |
300 | 312 | uint8_t o_v, o_p, o_cc; |
313 | + uint16_t min_len = 0; | |
301 | 314 | AVDT_REPORT_TYPE pt; |
302 | 315 | tAVDT_REPORT_DATA report; |
303 | 316 | |
304 | 317 | AVDT_TRACE_DEBUG("%s", __func__); |
305 | 318 | if (p_scb->cs.p_report_cback) { |
306 | 319 | /* parse report packet header */ |
320 | + min_len += 8; | |
321 | + if (min_len > len) { | |
322 | + android_errorWriteLog(0x534e4554, "111450156"); | |
323 | + AVDT_TRACE_WARNING( | |
324 | + "%s: hdl packet length %d too short: must be at least %d", __func__, | |
325 | + len, min_len); | |
326 | + goto avdt_scb_hdl_report_exit; | |
327 | + } | |
307 | 328 | AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc); |
308 | 329 | pt = *p++; |
309 | 330 | p += 2; |
@@ -311,6 +332,14 @@ uint8_t* avdt_scb_hdl_report(tAVDT_SCB* p_scb, uint8_t* p, uint16_t len) { | ||
311 | 332 | |
312 | 333 | switch (pt) { |
313 | 334 | case AVDT_RTCP_PT_SR: /* the packet type - SR (Sender Report) */ |
335 | + min_len += 20; | |
336 | + if (min_len > len) { | |
337 | + android_errorWriteLog(0x534e4554, "111450156"); | |
338 | + AVDT_TRACE_WARNING( | |
339 | + "%s: hdl packet length %d too short: must be at least %d", | |
340 | + __func__, len, min_len); | |
341 | + goto avdt_scb_hdl_report_exit; | |
342 | + } | |
314 | 343 | BE_STREAM_TO_UINT32(report.sr.ntp_sec, p); |
315 | 344 | BE_STREAM_TO_UINT32(report.sr.ntp_frac, p); |
316 | 345 | BE_STREAM_TO_UINT32(report.sr.rtp_time, p); |
@@ -319,6 +348,14 @@ uint8_t* avdt_scb_hdl_report(tAVDT_SCB* p_scb, uint8_t* p, uint16_t len) { | ||
319 | 348 | break; |
320 | 349 | |
321 | 350 | case AVDT_RTCP_PT_RR: /* the packet type - RR (Receiver Report) */ |
351 | + min_len += 20; | |
352 | + if (min_len > len) { | |
353 | + android_errorWriteLog(0x534e4554, "111450156"); | |
354 | + AVDT_TRACE_WARNING( | |
355 | + "%s: hdl packet length %d too short: must be at least %d", | |
356 | + __func__, len, min_len); | |
357 | + goto avdt_scb_hdl_report_exit; | |
358 | + } | |
322 | 359 | report.rr.frag_lost = *p; |
323 | 360 | BE_STREAM_TO_UINT32(report.rr.packet_lost, p); |
324 | 361 | report.rr.packet_lost &= 0xFFFFFF; |
@@ -330,9 +367,25 @@ uint8_t* avdt_scb_hdl_report(tAVDT_SCB* p_scb, uint8_t* p, uint16_t len) { | ||
330 | 367 | |
331 | 368 | case AVDT_RTCP_PT_SDES: /* the packet type - SDES (Source Description) */ |
332 | 369 | uint8_t sdes_type; |
370 | + min_len += 1; | |
371 | + if (min_len > len) { | |
372 | + android_errorWriteLog(0x534e4554, "111450156"); | |
373 | + AVDT_TRACE_WARNING( | |
374 | + "%s: hdl packet length %d too short: must be at least %d", | |
375 | + __func__, len, min_len); | |
376 | + goto avdt_scb_hdl_report_exit; | |
377 | + } | |
333 | 378 | BE_STREAM_TO_UINT8(sdes_type, p); |
334 | 379 | if (sdes_type == AVDT_RTCP_SDES_CNAME) { |
335 | 380 | uint8_t name_length; |
381 | + min_len += 1; | |
382 | + if (min_len > len) { | |
383 | + android_errorWriteLog(0x534e4554, "111450156"); | |
384 | + AVDT_TRACE_WARNING( | |
385 | + "%s: hdl packet length %d too short: must be at least %d", | |
386 | + __func__, len, min_len); | |
387 | + goto avdt_scb_hdl_report_exit; | |
388 | + } | |
336 | 389 | BE_STREAM_TO_UINT8(name_length, p); |
337 | 390 | if (name_length > len - 2 || name_length > AVDT_MAX_CNAME_SIZE) { |
338 | 391 | result = AVDT_BAD_PARAMS; |
@@ -340,6 +393,13 @@ uint8_t* avdt_scb_hdl_report(tAVDT_SCB* p_scb, uint8_t* p, uint16_t len) { | ||
340 | 393 | BE_STREAM_TO_ARRAY(p, &(report.cname[0]), name_length); |
341 | 394 | } |
342 | 395 | } else { |
396 | + if (min_len + 1 > len) { | |
397 | + android_errorWriteLog(0x534e4554, "111450156"); | |
398 | + AVDT_TRACE_WARNING( | |
399 | + "%s: hdl packet length %d too short: must be at least %d", | |
400 | + __func__, len, min_len + 2); | |
401 | + goto avdt_scb_hdl_report_exit; | |
402 | + } | |
343 | 403 | AVDT_TRACE_WARNING(" - SDES SSRC=0x%08x sc=%d %d len=%d %s", ssrc, |
344 | 404 | o_cc, *p, *(p + 1), p + 2); |
345 | 405 | result = AVDT_BUSY; |
@@ -354,6 +414,7 @@ uint8_t* avdt_scb_hdl_report(tAVDT_SCB* p_scb, uint8_t* p, uint16_t len) { | ||
354 | 414 | if (result == AVDT_SUCCESS) |
355 | 415 | (*p_scb->cs.p_report_cback)(avdt_scb_to_hdl(p_scb), pt, &report); |
356 | 416 | } |
417 | +avdt_scb_hdl_report_exit: | |
357 | 418 | p_start += len; |
358 | 419 | return p_start; |
359 | 420 | } |
@@ -449,12 +449,23 @@ void mca_ccb_hdl_rsp(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { | ||
449 | 449 | tMCA_RESULT result = MCA_BAD_HANDLE; |
450 | 450 | tMCA_TC_TBL* p_tbl; |
451 | 451 | |
452 | - if (p_ccb->p_tx_req) { | |
452 | + if (p_pkt->len < sizeof(evt_data.hdr.op_code) + | |
453 | + sizeof(evt_data.rsp.rsp_code) + | |
454 | + sizeof(evt_data.hdr.mdl_id)) { | |
455 | + android_errorWriteLog(0x534e4554, "116319076"); | |
456 | + MCA_TRACE_ERROR("%s: Response packet is too short", __func__); | |
457 | + } else if (p_ccb->p_tx_req) { | |
453 | 458 | /* verify that the received response matches the sent request */ |
454 | 459 | p = (uint8_t*)(p_pkt + 1) + p_pkt->offset; |
455 | 460 | evt_data.hdr.op_code = *p++; |
456 | - if ((evt_data.hdr.op_code == 0) || | |
457 | - ((p_ccb->p_tx_req->op_code + 1) == evt_data.hdr.op_code)) { | |
461 | + if ((evt_data.hdr.op_code == MCA_OP_MDL_CREATE_RSP) && | |
462 | + (p_pkt->len < | |
463 | + sizeof(evt_data.hdr.op_code) + sizeof(evt_data.rsp.rsp_code) + | |
464 | + sizeof(evt_data.hdr.mdl_id) + sizeof(evt_data.create_cfm.cfg))) { | |
465 | + android_errorWriteLog(0x534e4554, "116319076"); | |
466 | + MCA_TRACE_ERROR("%s: MDL Create Response packet is too short", __func__); | |
467 | + } else if ((evt_data.hdr.op_code == 0) || | |
468 | + ((p_ccb->p_tx_req->op_code + 1) == evt_data.hdr.op_code)) { | |
458 | 469 | evt_data.rsp.rsp_code = *p++; |
459 | 470 | mca_stop_timer(p_ccb); |
460 | 471 | BE_STREAM_TO_UINT16(evt_data.hdr.mdl_id, p); |
@@ -53,7 +53,7 @@ static void process_service_search_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply, | ||
53 | 53 | static uint8_t* save_attr_seq(tCONN_CB* p_ccb, uint8_t* p, uint8_t* p_msg_end); |
54 | 54 | static tSDP_DISC_REC* add_record(tSDP_DISCOVERY_DB* p_db, |
55 | 55 | const RawAddress& p_bda); |
56 | -static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | |
56 | +static uint8_t* add_attr(uint8_t* p, uint8_t* p_end, tSDP_DISCOVERY_DB* p_db, | |
57 | 57 | tSDP_DISC_REC* p_rec, uint16_t attr_id, |
58 | 58 | tSDP_DISC_ATTR* p_parent_attr, uint8_t nest_level); |
59 | 59 |
@@ -767,7 +767,7 @@ static uint8_t* save_attr_seq(tCONN_CB* p_ccb, uint8_t* p, uint8_t* p_msg_end) { | ||
767 | 767 | BE_STREAM_TO_UINT16(attr_id, p); |
768 | 768 | |
769 | 769 | /* Now, add the attribute value */ |
770 | - p = add_attr(p, p_ccb->p_db, p_rec, attr_id, NULL, 0); | |
770 | + p = add_attr(p, p_seq_end, p_ccb->p_db, p_rec, attr_id, NULL, 0); | |
771 | 771 | |
772 | 772 | if (!p) { |
773 | 773 | SDP_TRACE_WARNING("SDP - DB full add_attr"); |
@@ -827,7 +827,7 @@ tSDP_DISC_REC* add_record(tSDP_DISCOVERY_DB* p_db, const RawAddress& p_bda) { | ||
827 | 827 | * Returns pointer to next byte in data stream |
828 | 828 | * |
829 | 829 | ******************************************************************************/ |
830 | -static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | |
830 | +static uint8_t* add_attr(uint8_t* p, uint8_t* p_end, tSDP_DISCOVERY_DB* p_db, | |
831 | 831 | tSDP_DISC_REC* p_rec, uint16_t attr_id, |
832 | 832 | tSDP_DISC_ATTR* p_parent_attr, uint8_t nest_level) { |
833 | 833 | tSDP_DISC_ATTR* p_attr; |
@@ -836,7 +836,7 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | ||
836 | 836 | uint16_t attr_type; |
837 | 837 | uint16_t id; |
838 | 838 | uint8_t type; |
839 | - uint8_t* p_end; | |
839 | + uint8_t* p_attr_end; | |
840 | 840 | uint8_t is_additional_list = nest_level & SDP_ADDITIONAL_LIST_MASK; |
841 | 841 | |
842 | 842 | nest_level &= ~(SDP_ADDITIONAL_LIST_MASK); |
@@ -853,6 +853,13 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | ||
853 | 853 | else |
854 | 854 | total_len = sizeof(tSDP_DISC_ATTR); |
855 | 855 | |
856 | + p_attr_end = p + attr_len; | |
857 | + if (p_attr_end > p_end) { | |
858 | + android_errorWriteLog(0x534e4554, "115900043"); | |
859 | + SDP_TRACE_WARNING("%s: SDP - Attribute length beyond p_end", __func__); | |
860 | + return NULL; | |
861 | + } | |
862 | + | |
856 | 863 | /* Ensure it is a multiple of 4 */ |
857 | 864 | total_len = (total_len + 3) & ~3; |
858 | 865 |
@@ -876,18 +883,17 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | ||
876 | 883 | * sub-attributes */ |
877 | 884 | p_db->p_free_mem += sizeof(tSDP_DISC_ATTR); |
878 | 885 | p_db->mem_free -= sizeof(tSDP_DISC_ATTR); |
879 | - p_end = p + attr_len; | |
880 | 886 | total_len = 0; |
881 | 887 | |
882 | 888 | /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d(list)", nest_level); */ |
883 | 889 | if (nest_level >= MAX_NEST_LEVELS) { |
884 | 890 | SDP_TRACE_ERROR("SDP - attr nesting too deep"); |
885 | - return (p_end); | |
891 | + return p_attr_end; | |
886 | 892 | } |
887 | 893 | |
888 | 894 | /* Now, add the list entry */ |
889 | - p = add_attr(p, p_db, p_rec, ATTR_ID_PROTOCOL_DESC_LIST, p_attr, | |
890 | - (uint8_t)(nest_level + 1)); | |
895 | + p = add_attr(p, p_end, p_db, p_rec, ATTR_ID_PROTOCOL_DESC_LIST, | |
896 | + p_attr, (uint8_t)(nest_level + 1)); | |
891 | 897 | |
892 | 898 | break; |
893 | 899 | } |
@@ -946,7 +952,7 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | ||
946 | 952 | break; |
947 | 953 | default: |
948 | 954 | SDP_TRACE_WARNING("SDP - bad len in UUID attr: %d", attr_len); |
949 | - return (p + attr_len); | |
955 | + return p_attr_end; | |
950 | 956 | } |
951 | 957 | break; |
952 | 958 |
@@ -956,22 +962,22 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | ||
956 | 962 | * sub-attributes */ |
957 | 963 | p_db->p_free_mem += sizeof(tSDP_DISC_ATTR); |
958 | 964 | p_db->mem_free -= sizeof(tSDP_DISC_ATTR); |
959 | - p_end = p + attr_len; | |
960 | 965 | total_len = 0; |
961 | 966 | |
962 | 967 | /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d", nest_level); */ |
963 | 968 | if (nest_level >= MAX_NEST_LEVELS) { |
964 | 969 | SDP_TRACE_ERROR("SDP - attr nesting too deep"); |
965 | - return (p_end); | |
970 | + return p_attr_end; | |
966 | 971 | } |
967 | 972 | if (is_additional_list != 0 || |
968 | 973 | attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS) |
969 | 974 | nest_level |= SDP_ADDITIONAL_LIST_MASK; |
970 | 975 | /* SDP_TRACE_DEBUG ("SDP - attr nest level:0x%x(finish)", nest_level); */ |
971 | 976 | |
972 | - while (p < p_end) { | |
977 | + while (p < p_attr_end) { | |
973 | 978 | /* Now, add the list entry */ |
974 | - p = add_attr(p, p_db, p_rec, 0, p_attr, (uint8_t)(nest_level + 1)); | |
979 | + p = add_attr(p, p_end, p_db, p_rec, 0, p_attr, | |
980 | + (uint8_t)(nest_level + 1)); | |
975 | 981 | |
976 | 982 | if (!p) return (NULL); |
977 | 983 | } |
@@ -989,7 +995,7 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, | ||
989 | 995 | break; |
990 | 996 | default: |
991 | 997 | SDP_TRACE_WARNING("SDP - bad len in boolean attr: %d", attr_len); |
992 | - return (p + attr_len); | |
998 | + return p_attr_end; | |
993 | 999 | } |
994 | 1000 | break; |
995 | 1001 |