• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

system/bt


コミットメタ情報

リビジョン93f10607a7a6924e743f9ae758a773e218eb2204 (tree)
日時2019-01-18 19:52:46
作者Myles Watson <mylesgw@goog...>
コミッターVasyl Gello

ログメッセージ

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 b8a5081b00fc9730092d8392786f3f4e659cb602)

変更サマリ

差分

--- a/stack/sdp/sdp_discovery.c
+++ b/stack/sdp/sdp_discovery.c
@@ -54,7 +54,7 @@ static void process_service_search_attr_rsp (tCONN_CB* p_ccb, uint8_t*
5454 uint8_t* p_reply_end);
5555 static UINT8 *save_attr_seq (tCONN_CB *p_ccb, UINT8 *p, UINT8 *p_msg_end);
5656 static tSDP_DISC_REC *add_record (tSDP_DISCOVERY_DB *p_db, BD_ADDR p_bda);
57-static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
57+static UINT8 *add_attr (UINT8 *p, UINT8 *p_end, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
5858 UINT16 attr_id, tSDP_DISC_ATTR *p_parent_attr, UINT8 nest_level);
5959
6060 /* Safety check in case we go crazy */
@@ -831,7 +831,7 @@ static UINT8 *save_attr_seq (tCONN_CB *p_ccb, UINT8 *p, UINT8 *p_msg_end)
831831 BE_STREAM_TO_UINT16 (attr_id, p);
832832
833833 /* Now, add the attribute value */
834- p = add_attr (p, p_ccb->p_db, p_rec, attr_id, NULL, 0);
834+ p = add_attr (p, p_seq_end, p_ccb->p_db, p_rec, attr_id, NULL, 0);
835835
836836 if (!p)
837837 {
@@ -897,7 +897,7 @@ tSDP_DISC_REC *add_record (tSDP_DISCOVERY_DB *p_db, BD_ADDR p_bda)
897897 ** Returns pointer to next byte in data stream
898898 **
899899 *******************************************************************************/
900-static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
900+static UINT8 *add_attr (UINT8 *p, UINT8 *p_end, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
901901 UINT16 attr_id, tSDP_DISC_ATTR *p_parent_attr, UINT8 nest_level)
902902 {
903903 tSDP_DISC_ATTR *p_attr;
@@ -906,7 +906,7 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
906906 UINT16 attr_type;
907907 UINT16 id;
908908 UINT8 type;
909- UINT8 *p_end;
909+ UINT8 *p_attr_end;
910910 UINT8 is_additional_list = nest_level & SDP_ADDITIONAL_LIST_MASK;
911911
912912 nest_level &= ~(SDP_ADDITIONAL_LIST_MASK);
@@ -923,6 +923,14 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
923923 else
924924 total_len = sizeof (tSDP_DISC_ATTR);
925925
926+ p_attr_end = p + attr_len;
927+ if (p_attr_end > p_end)
928+ {
929+ android_errorWriteLog(0x534e4554, "115900043");
930+ SDP_TRACE_WARNING("%s: SDP - Attribute length beyond p_end", __func__);
931+ return NULL;
932+ }
933+
926934 /* Ensure it is a multiple of 4 */
927935 total_len = (total_len + 3) & ~3;
928936
@@ -949,18 +957,18 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
949957 /* Reserve the memory for the attribute now, as we need to add sub-attributes */
950958 p_db->p_free_mem += sizeof (tSDP_DISC_ATTR);
951959 p_db->mem_free -= sizeof (tSDP_DISC_ATTR);
952- p_end = p + attr_len;
953960 total_len = 0;
954961
955962 /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d(list)", nest_level); */
956963 if (nest_level >= MAX_NEST_LEVELS)
957964 {
958965 SDP_TRACE_ERROR ("SDP - attr nesting too deep");
959- return (p_end);
966+ return p_attr_end;
960967 }
961968
962969 /* Now, add the list entry */
963- p = add_attr (p, p_db, p_rec, ATTR_ID_PROTOCOL_DESC_LIST, p_attr, (UINT8)(nest_level + 1));
970+ p = add_attr (p, p_end, p_db, p_rec, ATTR_ID_PROTOCOL_DESC_LIST,
971+ p_attr, (UINT8)(nest_level + 1));
964972
965973 break;
966974 }
@@ -1033,7 +1041,7 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
10331041 break;
10341042 default:
10351043 SDP_TRACE_WARNING ("SDP - bad len in UUID attr: %d", attr_len);
1036- return (p + attr_len);
1044+ return p_attr_end;
10371045 }
10381046 break;
10391047
@@ -1042,23 +1050,22 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
10421050 /* Reserve the memory for the attribute now, as we need to add sub-attributes */
10431051 p_db->p_free_mem += sizeof (tSDP_DISC_ATTR);
10441052 p_db->mem_free -= sizeof (tSDP_DISC_ATTR);
1045- p_end = p + attr_len;
10461053 total_len = 0;
10471054
10481055 /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d", nest_level); */
10491056 if (nest_level >= MAX_NEST_LEVELS)
10501057 {
10511058 SDP_TRACE_ERROR ("SDP - attr nesting too deep");
1052- return (p_end);
1059+ return p_attr_end;
10531060 }
10541061 if(is_additional_list != 0 || attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS)
10551062 nest_level |= SDP_ADDITIONAL_LIST_MASK;
10561063 /* SDP_TRACE_DEBUG ("SDP - attr nest level:0x%x(finish)", nest_level); */
10571064
1058- while (p < p_end)
1065+ while (p < p_attr_end)
10591066 {
10601067 /* Now, add the list entry */
1061- p = add_attr (p, p_db, p_rec, 0, p_attr, (UINT8)(nest_level + 1));
1068+ p = add_attr (p, p_end, p_db, p_rec, 0, p_attr, (UINT8)(nest_level + 1));
10621069
10631070 if (!p)
10641071 return (NULL);
@@ -1078,7 +1085,7 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
10781085 break;
10791086 default:
10801087 SDP_TRACE_WARNING ("SDP - bad len in boolean attr: %d", attr_len);
1081- return (p + attr_len);
1088+ return p_attr_end;
10821089 }
10831090 break;
10841091