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

Commit 8af1a3e4 authored by Chienyuan's avatar Chienyuan Committed by Chienyuan Huang
Browse files

DO NOT MERGE Add mutex for std::map in btif_av.cc

TAG: #security
Bug: 169252501
Test: compilation
Ignore-AOSP-First: security fix
Change-Id: I592c0a9c0e77869999357611aa99f3d9bc53b8b6
parent 21b68a89
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <base/strings/stringprintf.h>
#include <base/strings/stringprintf.h>
#include <string.h>
#include <string.h>
#include <map>
#include <map>
#include <mutex>


#include <hardware/bluetooth.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_av.h>
#include <hardware/bt_av.h>
@@ -530,6 +531,7 @@ class BtifAvSource {
  std::set<RawAddress> silenced_peers_;
  std::set<RawAddress> silenced_peers_;
  RawAddress active_peer_;
  RawAddress active_peer_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::mutex mutex_;
};
};


class BtifAvSink {
class BtifAvSink {
@@ -647,6 +649,7 @@ class BtifAvSink {
  std::map<RawAddress, BtifAvPeer*> peers_;
  std::map<RawAddress, BtifAvPeer*> peers_;
  RawAddress active_peer_;
  RawAddress active_peer_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::mutex mutex_;
};
};


/*****************************************************************************
/*****************************************************************************
@@ -1023,6 +1026,7 @@ BtifAvPeer* BtifAvSource::FindPeerByPeerId(uint8_t peer_id) {


BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
                                           tBTA_AV_HNDL bta_handle) {
                                           tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
                   peer_address.ToString().c_str(), bta_handle);
                   peer_address.ToString().c_str(), bta_handle);


@@ -1122,6 +1126,7 @@ void BtifAvSource::RegisterAllBtaHandles() {
}
}


void BtifAvSource::DeregisterAllBtaHandles() {
void BtifAvSource::DeregisterAllBtaHandles() {
  std::unique_lock<std::mutex> lock(mutex_);
  for (auto it : peer_id2bta_handle_) {
  for (auto it : peer_id2bta_handle_) {
    tBTA_AV_HNDL bta_handle = it.second;
    tBTA_AV_HNDL bta_handle = it.second;
    BTA_AvDeregister(bta_handle);
    BTA_AvDeregister(bta_handle);
@@ -1131,6 +1136,7 @@ void BtifAvSource::DeregisterAllBtaHandles() {


void BtifAvSource::BtaHandleRegistered(uint8_t peer_id,
void BtifAvSource::BtaHandleRegistered(uint8_t peer_id,
                                       tBTA_AV_HNDL bta_handle) {
                                       tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  peer_id2bta_handle_.insert(std::make_pair(peer_id, bta_handle));
  peer_id2bta_handle_.insert(std::make_pair(peer_id, bta_handle));


  // Set the BTA Handle for the Peer (if exists)
  // Set the BTA Handle for the Peer (if exists)
@@ -1210,6 +1216,7 @@ BtifAvPeer* BtifAvSink::FindPeerByPeerId(uint8_t peer_id) {


BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
                                         tBTA_AV_HNDL bta_handle) {
                                         tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
                   peer_address.ToString().c_str(), bta_handle);
                   peer_address.ToString().c_str(), bta_handle);


@@ -1313,6 +1320,7 @@ void BtifAvSink::RegisterAllBtaHandles() {
}
}


void BtifAvSink::DeregisterAllBtaHandles() {
void BtifAvSink::DeregisterAllBtaHandles() {
  std::unique_lock<std::mutex> lock(mutex_);
  for (auto it : peer_id2bta_handle_) {
  for (auto it : peer_id2bta_handle_) {
    tBTA_AV_HNDL bta_handle = it.second;
    tBTA_AV_HNDL bta_handle = it.second;
    BTA_AvDeregister(bta_handle);
    BTA_AvDeregister(bta_handle);
@@ -1321,6 +1329,7 @@ void BtifAvSink::DeregisterAllBtaHandles() {
}
}


void BtifAvSink::BtaHandleRegistered(uint8_t peer_id, tBTA_AV_HNDL bta_handle) {
void BtifAvSink::BtaHandleRegistered(uint8_t peer_id, tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  peer_id2bta_handle_.insert(std::make_pair(peer_id, bta_handle));
  peer_id2bta_handle_.insert(std::make_pair(peer_id, bta_handle));


  // Set the BTA Handle for the Peer (if exists)
  // Set the BTA Handle for the Peer (if exists)