From 52766777e7f62a0fcda859394a7949e15a262b9f Mon Sep 17 00:00:00 2001 From: Himanshu Rawat Date: Mon, 17 Mar 2025 21:48:53 -0700 Subject: Check for invalid handle before looking up device by handle When invalid connection handle is passed to btm_find_dev_by_handle(), it returns the first device which does not have any of the transports connected. Test: mmm packages/modules/Bluetooth Flag: EXEMPT trivial fix Bug: 399122843 Change-Id: Idedd4a65ed4517ae6bee7efda9b0f87b7096a8c2 --- system/stack/btm/btm_dev.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/stack/btm/btm_dev.cc b/system/stack/btm/btm_dev.cc index 92dc80e1ab..992a59236c 100644 --- a/system/stack/btm/btm_dev.cc +++ b/system/stack/btm/btm_dev.cc @@ -326,6 +326,10 @@ static bool is_handle_equal(void* data, void* context) { * ******************************************************************************/ tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle) { + if (handle == HCI_INVALID_HANDLE) { + return nullptr; + } + if (btm_sec_cb.sec_dev_rec == nullptr) { return nullptr; } @@ -335,7 +339,7 @@ tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle) { return static_cast(list_node(n)); } - return NULL; + return nullptr; } static bool is_not_same_identity_or_pseudo_address(void* data, void* context) { -- cgit v1.2.3-59-g8ed1b