• 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

修订版70b6fc4e67b4163130985808b062a749eb2cd644 (tree)
时间2018-11-27 02:19:49
作者Myles Watson <mylesgw@goog...>
Commiterandroid-build-team Robot

Log Message

DO NOT MERGE: SDP: Check p_end in save_attr_seq and add_attr

Bug: 115900043
Test: Sanity pairing and SDP PTS
Change-Id: Ib642f79ed22b65ede5ff786cb1e163d172480f11
(cherry picked from commit 2aad270709f01481e91f7fdaafbebee49130cd28)

更改概述

差异

--- a/stack/sdp/sdp_discovery.cc
+++ b/stack/sdp/sdp_discovery.cc
@@ -53,7 +53,7 @@ static void process_service_search_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply,
5353 static uint8_t* save_attr_seq(tCONN_CB* p_ccb, uint8_t* p, uint8_t* p_msg_end);
5454 static tSDP_DISC_REC* add_record(tSDP_DISCOVERY_DB* p_db,
5555 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,
5757 tSDP_DISC_REC* p_rec, uint16_t attr_id,
5858 tSDP_DISC_ATTR* p_parent_attr, uint8_t nest_level);
5959
@@ -767,7 +767,7 @@ static uint8_t* save_attr_seq(tCONN_CB* p_ccb, uint8_t* p, uint8_t* p_msg_end) {
767767 BE_STREAM_TO_UINT16(attr_id, p);
768768
769769 /* 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);
771771
772772 if (!p) {
773773 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) {
827827 * Returns pointer to next byte in data stream
828828 *
829829 ******************************************************************************/
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,
831831 tSDP_DISC_REC* p_rec, uint16_t attr_id,
832832 tSDP_DISC_ATTR* p_parent_attr, uint8_t nest_level) {
833833 tSDP_DISC_ATTR* p_attr;
@@ -836,7 +836,7 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db,
836836 uint16_t attr_type;
837837 uint16_t id;
838838 uint8_t type;
839- uint8_t* p_end;
839+ uint8_t* p_attr_end;
840840 uint8_t is_additional_list = nest_level & SDP_ADDITIONAL_LIST_MASK;
841841
842842 nest_level &= ~(SDP_ADDITIONAL_LIST_MASK);
@@ -853,6 +853,13 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db,
853853 else
854854 total_len = sizeof(tSDP_DISC_ATTR);
855855
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+
856863 /* Ensure it is a multiple of 4 */
857864 total_len = (total_len + 3) & ~3;
858865
@@ -876,18 +883,17 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db,
876883 * sub-attributes */
877884 p_db->p_free_mem += sizeof(tSDP_DISC_ATTR);
878885 p_db->mem_free -= sizeof(tSDP_DISC_ATTR);
879- p_end = p + attr_len;
880886 total_len = 0;
881887
882888 /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d(list)", nest_level); */
883889 if (nest_level >= MAX_NEST_LEVELS) {
884890 SDP_TRACE_ERROR("SDP - attr nesting too deep");
885- return (p_end);
891+ return p_attr_end;
886892 }
887893
888894 /* 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));
891897
892898 break;
893899 }
@@ -946,7 +952,7 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db,
946952 break;
947953 default:
948954 SDP_TRACE_WARNING("SDP - bad len in UUID attr: %d", attr_len);
949- return (p + attr_len);
955+ return p_attr_end;
950956 }
951957 break;
952958
@@ -956,22 +962,22 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db,
956962 * sub-attributes */
957963 p_db->p_free_mem += sizeof(tSDP_DISC_ATTR);
958964 p_db->mem_free -= sizeof(tSDP_DISC_ATTR);
959- p_end = p + attr_len;
960965 total_len = 0;
961966
962967 /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d", nest_level); */
963968 if (nest_level >= MAX_NEST_LEVELS) {
964969 SDP_TRACE_ERROR("SDP - attr nesting too deep");
965- return (p_end);
970+ return p_attr_end;
966971 }
967972 if (is_additional_list != 0 ||
968973 attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS)
969974 nest_level |= SDP_ADDITIONAL_LIST_MASK;
970975 /* SDP_TRACE_DEBUG ("SDP - attr nest level:0x%x(finish)", nest_level); */
971976
972- while (p < p_end) {
977+ while (p < p_attr_end) {
973978 /* 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));
975981
976982 if (!p) return (NULL);
977983 }
@@ -989,7 +995,7 @@ static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db,
989995 break;
990996 default:
991997 SDP_TRACE_WARNING("SDP - bad len in boolean attr: %d", attr_len);
992- return (p + attr_len);
998+ return p_attr_end;
993999 }
9941000 break;
9951001