aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-10-04 18:07:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-10-04 18:07:23 +0000
commit62eb043512174b2b1b175cd6c8f78a572c9bf5c8 (patch)
treee743c543f7569c0b844da15950ab503fc1729507
parent5eed4c187950ae3b0d5b53f217cd1c8166f18f75 (diff)
parent5e487c24ebe1e48365320c8445ef874572e7e1e3 (diff)
downloadbt-62eb043512174b2b1b175cd6c8f78a572c9bf5c8.tar.gz
Merge cherrypicks of [17530409, 19501977] into rvc-platform-release. am: 5e487c24eb
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/bt/+/19662670 Change-Id: I1bc0fe571763e170e7e108b42f672cff0bf98303 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--stack/avdt/avdt_msg.cc4
-rw-r--r--stack/avrc/avrc_pars_ct.cc27
-rw-r--r--stack/test/stack_avrcp_test.cc50
3 files changed, 76 insertions, 5 deletions
diff --git a/stack/avdt/avdt_msg.cc b/stack/avdt/avdt_msg.cc
index 33fbfa744..406f7f7ba 100644
--- a/stack/avdt/avdt_msg.cc
+++ b/stack/avdt/avdt_msg.cc
@@ -1251,6 +1251,10 @@ BT_HDR* avdt_msg_asmbl(AvdtpCcb* p_ccb, BT_HDR* p_buf) {
* would have allocated smaller buffer.
*/
p_ccb->p_rx_msg = (BT_HDR*)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
+ if (sizeof(BT_HDR) + p_buf->offset + p_buf->len > BT_DEFAULT_BUFFER_SIZE) {
+ android_errorWriteLog(0x534e4554, "232023771");
+ return NULL;
+ }
memcpy(p_ccb->p_rx_msg, p_buf, sizeof(BT_HDR) + p_buf->offset + p_buf->len);
/* Free original buffer */
diff --git a/stack/avrc/avrc_pars_ct.cc b/stack/avrc/avrc_pars_ct.cc
index 8a4cf3034..09828bffd 100644
--- a/stack/avrc/avrc_pars_ct.cc
+++ b/stack/avrc/avrc_pars_ct.cc
@@ -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;
- int min_len = 0;
+ uint16_t min_len = 0;
/* read the entire packet len */
BE_STREAM_TO_UINT16(pkt_len, p);
@@ -380,8 +380,14 @@ 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,
@@ -444,8 +450,14 @@ 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);
@@ -815,8 +827,12 @@ 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);
- min_len += p_attrs[i].name.str_len;
- if (len < min_len) {
+ 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) {
for (int j = 0; j < i; j++) {
osi_free(p_attrs[j].name.p_str);
}
@@ -824,6 +840,7 @@ static tAVRC_STS avrc_ctrl_pars_vendor_rsp(tAVRC_MSG_VENDOR* p_msg,
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);
diff --git a/stack/test/stack_avrcp_test.cc b/stack/test/stack_avrcp_test.cc
index 72ec45f29..e731e98b7 100644
--- a/stack/test/stack_avrcp_test.cc
+++ b/stack/test/stack_avrcp_test.cc
@@ -27,6 +27,56 @@ class StackAvrcpTest : public ::testing::Test {
virtual ~StackAvrcpTest() = default;
};
+TEST_F(StackAvrcpTest, test_avrcp_ctrl_parse_vendor_rsp) {
+ uint8_t scratch_buf[512]{};
+ uint16_t scratch_buf_len = 512;
+ tAVRC_MSG msg{};
+ tAVRC_RESPONSE result{};
+ uint8_t vendor_rsp_buf[512]{};
+
+ msg.hdr.opcode = AVRC_OP_VENDOR;
+ msg.hdr.ctype = AVRC_CMD_STATUS;
+
+ memset(vendor_rsp_buf, 0, sizeof(vendor_rsp_buf));
+ vendor_rsp_buf[0] = AVRC_PDU_GET_ELEMENT_ATTR;
+ uint8_t* p = &vendor_rsp_buf[2];
+ UINT16_TO_BE_STREAM(p, 0x0009); // parameter length
+ UINT8_TO_STREAM(p, 0x01); // number of attributes
+ UINT32_TO_STREAM(p, 0x00000000); // attribute ID
+ UINT16_TO_STREAM(p, 0x0000); // character set ID
+ UINT16_TO_STREAM(p, 0xffff); // attribute value length
+ msg.vendor.p_vendor_data = vendor_rsp_buf;
+ msg.vendor.vendor_len = 13;
+ EXPECT_EQ(
+ AVRC_Ctrl_ParsResponse(&msg, &result, scratch_buf, &scratch_buf_len),
+ AVRC_STS_INTERNAL_ERR);
+}
+
+TEST_F(StackAvrcpTest, test_avrcp_parse_browse_rsp) {
+ uint8_t scratch_buf[512]{};
+ uint16_t scratch_buf_len = 512;
+ tAVRC_MSG msg{};
+ tAVRC_RESPONSE result{};
+ uint8_t browse_rsp_buf[512]{};
+
+ msg.hdr.opcode = AVRC_OP_BROWSE;
+
+ memset(browse_rsp_buf, 0, sizeof(browse_rsp_buf));
+ browse_rsp_buf[0] = AVRC_PDU_GET_ITEM_ATTRIBUTES;
+ uint8_t* p = &browse_rsp_buf[1];
+ UINT16_TO_BE_STREAM(p, 0x000a); // parameter length;
+ UINT8_TO_STREAM(p, 0x04); // status
+ UINT8_TO_STREAM(p, 0x01); // number of attribute
+ UINT32_TO_STREAM(p, 0x00000000); // attribute ID
+ UINT16_TO_STREAM(p, 0x0000); // character set ID
+ UINT16_TO_STREAM(p, 0xffff); // attribute value length
+ msg.browse.p_browse_data = browse_rsp_buf;
+ msg.browse.browse_len = 13;
+ EXPECT_EQ(
+ AVRC_Ctrl_ParsResponse(&msg, &result, scratch_buf, &scratch_buf_len),
+ AVRC_STS_BAD_CMD);
+}
+
TEST_F(StackAvrcpTest, test_avrcp_parse_browse_cmd) {
uint8_t scratch_buf[512]{};
tAVRC_MSG msg{};