• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

修订版457d2c4ab906e1166e8b2e19bf4b57dcbfd4b3c8 (tree)
时间2018-11-27 02:19:57
作者Chienyuan <chienyuanhuang@goog...>
Commiterandroid-build-team Robot

Log Message

DO NOT MERGE HFP: Check AT command buffer boundary during parsing

* add p_end parameter to tBTA_AG_AT_CMD_CBACK, bta_ag_at_hsp_cback

and bta_ag_at_hfp_cback to indicate effective data range of p_arg

* add checks for buffer copy overflow in bta_ag_at_hsp_cback and

bta_ag_at_hfp_cback

* add packet legnth checks with p_end in bta_ag_parse_cmer
* add packet length checks with p_end in bta_ag_parse_bac

Bug: 112860487
Test: manual
Change-Id: I6bbbc2ba29ad025c7d3ba023d8191af6a11c4aa9
(cherry picked from commit 749063afebb8324276a47bdfbf320aa70f94a8ba)
(cherry picked from commit 9cb959d00d33737b399377cfc0f4070081d48f5e)

更改概述

差异

--- a/bta/ag/bta_ag_act.cc
+++ b/bta/ag/bta_ag_act.cc
@@ -58,7 +58,7 @@ const tBTA_SERVICE_MASK bta_ag_svc_mask[BTA_AG_NUM_IDX] = {
5858 BTA_HSP_SERVICE_MASK, BTA_HFP_SERVICE_MASK};
5959
6060 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,
6262 int16_t int_arg);
6363
6464 const tBTA_AG_ATCMD_CBACK bta_ag_at_cback_tbl[BTA_AG_NUM_IDX] = {
--- a/bta/ag/bta_ag_at.cc
+++ b/bta/ag/bta_ag_at.cc
@@ -26,6 +26,7 @@
2626
2727 #include "bt_common.h"
2828 #include "bta_ag_at.h"
29+#include "log/log.h"
2930 #include "utl.h"
3031
3132 /*****************************************************************************
@@ -76,7 +77,7 @@ void bta_ag_at_reinit(tBTA_AG_AT_CB* p_cb) {
7677 * Returns void
7778 *
7879 *****************************************************************************/
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) {
8081 uint16_t idx;
8182 uint8_t arg_type;
8283 char* p_arg;
@@ -92,6 +93,11 @@ void bta_ag_process_at(tBTA_AG_AT_CB* p_cb) {
9293 if (p_cb->p_at_tbl[idx].p_cmd[0] != 0) {
9394 /* start of argument is p + strlen matching command */
9495 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+ }
95101
96102 /* if no argument */
97103 if (p_arg[0] == 0) {
@@ -132,11 +138,11 @@ void bta_ag_process_at(tBTA_AG_AT_CB* p_cb) {
132138 (*p_cb->p_err_cback)(p_cb->p_user, false, NULL);
133139 } else {
134140 (*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);
136142 }
137143 } else {
138144 (*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);
140146 }
141147 }
142148 /* else error */
@@ -187,8 +193,9 @@ void bta_ag_at_parse(tBTA_AG_AT_CB* p_cb, char* p_buf, uint16_t len) {
187193 (p_cb->p_cmd_buf[0] == 'A' || p_cb->p_cmd_buf[0] == 'a') &&
188194 (p_cb->p_cmd_buf[1] == 'T' || p_cb->p_cmd_buf[1] == 't')) {
189195 p_save = p_cb->p_cmd_buf;
196+ char* p_end = p_cb->p_cmd_buf + p_cb->cmd_pos;
190197 p_cb->p_cmd_buf += 2;
191- bta_ag_process_at(p_cb);
198+ bta_ag_process_at(p_cb, p_end);
192199 p_cb->p_cmd_buf = p_save;
193200 }
194201
--- a/bta/ag/bta_ag_at.h
+++ b/bta/ag/bta_ag_at.h
@@ -55,7 +55,7 @@ typedef struct {
5555
5656 /* callback function executed when command is parsed */
5757 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,
5959 int16_t int_arg);
6060
6161 /* callback function executed to send "ERROR" result code */
--- a/bta/ag/bta_ag_cmd.cc
+++ b/bta/ag/bta_ag_cmd.cc
@@ -30,6 +30,7 @@
3030 #include "bta_ag_int.h"
3131 #include "bta_api.h"
3232 #include "bta_sys.h"
33+#include "log/log.h"
3334 #include "osi/include/log.h"
3435 #include "osi/include/osi.h"
3536 #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,
378379 * Returns true if parsed ok, false otherwise.
379380 *
380381 ******************************************************************************/
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) {
382383 int16_t n[4] = {-1, -1, -1, -1};
383384 int i;
384385 char* p;
385386
386- for (i = 0; i < 4; i++) {
387+ for (i = 0; i < 4; i++, p_s = p + 1) {
387388 /* 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++)
389390 ;
390391
391392 /* get integer value */
393+ if (p > p_end) {
394+ android_errorWriteLog(0x534e4554, "112860487");
395+ return false;
396+ }
392397 *p = 0;
393398 n[i] = utl_str2int(p_s);
394- p_s = p + 1;
395- if (p_s == 0) {
396- break;
397- }
398399 }
399400
400401 /* process values */
@@ -452,7 +453,8 @@ static uint8_t bta_ag_parse_chld(UNUSED_ATTR tBTA_AG_SCB* p_scb, char* p_s) {
452453 * Returns Returns bitmap of supported codecs.
453454 *
454455 ******************************************************************************/
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) {
456458 tBTA_AG_PEER_CODEC retval = BTA_AG_CODEC_NONE;
457459 uint16_t uuid_codec;
458460 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) {
460462
461463 while (p_s) {
462464 /* 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++)
464466 ;
465467
466468 /* get integre value */
469+ if (p > p_end) {
470+ android_errorWriteLog(0x534e4554, "112860487");
471+ break;
472+ }
467473 if (*p != 0) {
468474 *p = 0;
469475 cont = true;
@@ -597,7 +603,8 @@ void bta_ag_send_call_inds(tBTA_AG_SCB* p_scb, tBTA_AG_RES result) {
597603 *
598604 ******************************************************************************/
599605 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) {
601608 APPL_TRACE_DEBUG("AT cmd:%d arg_type:%d arg:%d arg:%s", command_id, arg_type,
602609 int_arg, p_arg);
603610
@@ -607,6 +614,13 @@ void bta_ag_at_hsp_cback(tBTA_AG_SCB* p_scb, uint16_t command_id,
607614 val.hdr.handle = bta_ag_scb_to_idx(p_scb);
608615 val.hdr.app_id = p_scb->app_id;
609616 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+ }
610624 strlcpy(val.str, p_arg, sizeof(val.str));
611625
612626 /* call callback with event */
@@ -836,7 +850,7 @@ static bool bta_ag_parse_biev_response(tBTA_AG_SCB* p_scb, tBTA_AG_VAL* val) {
836850 *
837851 ******************************************************************************/
838852 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) {
840854 tBTA_AG_VAL val;
841855 tBTA_AG_SCB* ag_scb;
842856 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,
856870 val.hdr.status = BTA_AG_SUCCESS;
857871 val.num = int_arg;
858872 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+ }
859880 strlcpy(val.str, p_arg, sizeof(val.str));
860881
861882 /**
@@ -1034,7 +1055,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
10341055
10351056 case BTA_AG_LOCAL_EVT_CMER:
10361057 /* 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)) {
10381059 bta_ag_send_ok(p_scb);
10391060
10401061 /* 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,
11951216 /* store available codecs from the peer */
11961217 if ((p_scb->peer_features & BTA_AG_PEER_FEAT_CODEC) &&
11971218 (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);
11991220 p_scb->codec_updated = true;
12001221
12011222 if (p_scb->peer_codecs & BTA_AG_CODEC_MSBC) {
--- a/bta/ag/bta_ag_int.h
+++ b/bta/ag/bta_ag_int.h
@@ -361,9 +361,11 @@ extern void bta_ag_sco_conn_rsp(tBTA_AG_SCB* p_scb,
361361
362362 /* AT command functions */
363363 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);
365366 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);
367369 extern void bta_ag_at_err_cback(tBTA_AG_SCB* p_scb, bool unknown, char* p_arg);
368370 extern bool bta_ag_inband_enabled(tBTA_AG_SCB* p_scb);
369371 extern void bta_ag_send_call_inds(tBTA_AG_SCB* p_scb, tBTA_AG_RES result);