Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e66b41d authored by Zongheng Wang's avatar Zongheng Wang Committed by Myles Watson
Browse files

SDP: disconnect if sdp_copy_raw_data fails

Our partners met with the problem with sdp_copy_raw_data updated in
CVE-2019-2116. When peer device responds with a wrong size,
sdp_copy_raw_data will not complete and won't trigger
disconnection. This CL enables the disconnection when a wrong size is
received.

Bug: 137239831
Bug: 117105007
Test: manual test
Change-Id: I9f0df8b2de28970e7d69b737ce5d363785183bf3
Merged-In: I9f0df8b2de28970e7d69b737ce5d363785183bf3
(cherry picked from commit 4e94f7ec)
parent 10edcaf6
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -336,11 +336,13 @@ static void process_service_search_rsp(tCONN_CB* p_ccb, uint8_t* p_reply,
 * Description      copy the raw data
 *
 *
 * Returns          void
 * Returns          bool
 *                          true if successful
 *                          false if not copied
 *
 ******************************************************************************/
#if (SDP_RAW_DATA_INCLUDED == TRUE)
static void sdp_copy_raw_data(tCONN_CB* p_ccb, bool offset) {
static bool sdp_copy_raw_data(tCONN_CB* p_ccb, bool offset) {
  unsigned int cpy_len, rem_len;
  uint32_t list_len;
  uint8_t* p;
@@ -371,11 +373,11 @@ static void sdp_copy_raw_data(tCONN_CB* p_ccb, bool offset) {
      p = sdpu_get_len_from_type(p, p_end, type, &list_len);
      if (p == NULL || (p + list_len) > p_end) {
        SDP_TRACE_WARNING("%s: bad length", __func__);
        return;
        return false;
      }
      if ((int)cpy_len < (p - old_p)) {
        SDP_TRACE_WARNING("%s: no bytes left for data", __func__);
        return;
        return false;
      }
      cpy_len -= (p - old_p);
    }
@@ -395,6 +397,7 @@ static void sdp_copy_raw_data(tCONN_CB* p_ccb, bool offset) {
    memcpy(&p_ccb->p_db->raw_data[p_ccb->p_db->raw_used], p, cpy_len);
    p_ccb->p_db->raw_used += cpy_len;
  }
  return true;
}
#endif

@@ -463,7 +466,11 @@ static void process_service_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply,
    } else {
#if (SDP_RAW_DATA_INCLUDED == TRUE)
      SDP_TRACE_WARNING("process_service_attr_rsp");
      sdp_copy_raw_data(p_ccb, false);
      if (!sdp_copy_raw_data(p_ccb, false)) {
        SDP_TRACE_ERROR("sdp_copy_raw_data failed");
        sdp_disconnect(p_ccb, SDP_ILLEGAL_PARAMETER);
      }

#endif

      /* Save the response in the database. Stop on any error */
@@ -688,7 +695,10 @@ static void process_service_search_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply,

#if (SDP_RAW_DATA_INCLUDED == TRUE)
  SDP_TRACE_WARNING("process_service_search_attr_rsp");
  sdp_copy_raw_data(p_ccb, true);
  if (!sdp_copy_raw_data(p_ccb, true)) {
    SDP_TRACE_ERROR("sdp_copy_raw_data failed");
    sdp_disconnect(p_ccb, SDP_ILLEGAL_PARAMETER);
  }
#endif

  p = &p_ccb->rsp_list[0];