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

Commit bfbb7583 authored by Chris Manton's avatar Chris Manton
Browse files

stack::btm::dev Check for sec device list nullptr

Bug: 320332353
Test: atest net_test_stack_btm
Flag: EXEMPT, null check
Change-Id: I875bc4048f76b7eb7b7a4e19399fbfd9fb20bd83
parent d7d2dd27
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1527,6 +1527,7 @@ cc_test {
        "test/btm/peer_packet_types_test.cc",
        "test/btm/sco_hci_test.cc",
        "test/btm/sco_pkt_status_test.cc",
        "test/btm/stack_btm_dev_test.cc",
        "test/btm/stack_btm_power_mode_test.cc",
        "test/btm/stack_btm_regression_tests.cc",
        "test/btm/stack_btm_sec_test.cc",
+6 −0
Original line number Diff line number Diff line
@@ -638,6 +638,12 @@ static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec(void) {
tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) {
  tBTM_SEC_DEV_REC* p_dev_rec = NULL;

  if (btm_sec_cb.sec_dev_rec == nullptr) {
    LOG_WARN(
        "Unable to allocate device record with destructed device record list");
    return nullptr;
  }

  if (list_length(btm_sec_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) {
    p_dev_rec = btm_find_oldest_dev_rec();
    wipe_secrets_and_remove(p_dev_rec);
+50 −0
Original line number Diff line number Diff line
/*
 *  Copyright 2024 The Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_sec_cb.h"
#include "test/common/mock_functions.h"
#include "test/mock/mock_main_shim_entry.h"

class StackBtmTest : public testing::Test {
 public:
 protected:
  void SetUp() override { reset_mock_function_count_map(); }
  void TearDown() override {}
};

class StackBtmDevTest : public StackBtmTest {
 protected:
  void SetUp() override { StackBtmTest::SetUp(); }
  void TearDown() override { StackBtmTest::TearDown(); }
};

TEST_F(StackBtmDevTest, btm_sec_allocate_dev_rec__no_list) {
  ASSERT_EQ(nullptr, btm_sec_allocate_dev_rec());
  ::btm_sec_cb.Init(BTM_SEC_MODE_SC);
  ::btm_sec_cb.Free();
  ASSERT_EQ(nullptr, btm_sec_allocate_dev_rec());
}

TEST_F(StackBtmDevTest, btm_sec_allocate_dev_rec__with_list) {
  ::btm_sec_cb.Init(BTM_SEC_MODE_SC);
  ASSERT_NE(nullptr, btm_sec_allocate_dev_rec());
  ::btm_sec_cb.Free();
}