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

Commit 192cbdb6 authored by Krzysztof Kopyściński's avatar Krzysztof Kopyściński
Browse files

has_client.cc: fix possible null pointer dereference in `Disconnect`

device could be null (not connected to profile)

Bug: 373981915
Flag: com.android.bluetooth.flags.hap_connect_only_requested_device
Test: atest --host --no-bazel-mode bluetooth_has_test
Change-Id: I2a48e58616b242252f41c1b5622f99b3ecf295c8
parent 9479db36
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -222,6 +222,11 @@ public:
    if (com::android::bluetooth::flags::hap_connect_only_requested_device()) {
      auto device =
              std::find_if(devices_.begin(), devices_.end(), HasDevice::MatchAddress(address));
      if (device == devices_.end()) {
        log::warn("Device not connected to profile{}", address);
        return;
      }

      auto conn_id = device->conn_id;
      auto is_connecting_actively = device->is_connecting_actively;

+13 −0
Original line number Diff line number Diff line
@@ -1195,7 +1195,20 @@ TEST_F(HasClientTest, test_connect_after_remove) {
  Mock::VerifyAndClearExpectations(&callbacks);
}

TEST_F(HasClientTest,
       test_disconnect_non_connected_without_hap_connect_only_requested_device_flag) {
  com::android::bluetooth::flags::provider_->hap_connect_only_requested_device(false);
  const RawAddress test_address = GetTestAddress(1);

  /* Override the default action to prevent us sendind the connected event */
  EXPECT_CALL(gatt_interface, Open(gatt_if, test_address, BTM_BLE_DIRECT_CONNECTION, _))
          .WillOnce(Return());
  HasClient::Get()->Connect(test_address);
  TestDisconnect(test_address, GATT_INVALID_CONN_ID);
}

TEST_F(HasClientTest, test_disconnect_non_connected) {
  com::android::bluetooth::flags::provider_->hap_connect_only_requested_device(true);
  const RawAddress test_address = GetTestAddress(1);

  /* Override the default action to prevent us sendind the connected event */