From bdb220fcfdbf2fe30b933f5aa7918cce317ff751 Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Wed, 13 Nov 2024 08:47:35 -0800 Subject: [PATCH] Fixed the crash bug b/369666780 PiperOrigin-RevId: 696151353 --- .../implementation/p2p_cluster_pcp_handler.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/connections/implementation/p2p_cluster_pcp_handler.cc b/connections/implementation/p2p_cluster_pcp_handler.cc index 06714df8..290f9183 100644 --- a/connections/implementation/p2p_cluster_pcp_handler.cc +++ b/connections/implementation/p2p_cluster_pcp_handler.cc @@ -343,6 +343,12 @@ void P2pClusterPcpHandler::BluetoothDeviceDiscoveredHandler( "p2p-bt-device-discovered", [this, client, service_id, device]() RUN_ON_PCP_HANDLER_THREAD() { + if (!device.IsValid()) { + NEARBY_LOGS(WARNING) << "BluetoothDeviceDiscoveredHandler: " + "Skipping the invalid Bluetooth device"; + return; + } + // Make sure we are still discovering before proceeding. if (!client->IsDiscovering()) { NEARBY_LOGS(WARNING) << "Skipping discovery of BluetoothDevice " @@ -388,6 +394,12 @@ void P2pClusterPcpHandler::BluetoothNameChangedHandler( "p2p-bt-name-changed", [this, client, service_id, device]() RUN_ON_PCP_HANDLER_THREAD() { // Make sure we are still discovering before proceeding. + if (!device.IsValid()) { + NEARBY_LOGS(WARNING) << "BluetoothNameChangedHandler: Skipping the " + "invalid Bluetooth device"; + return; + } + if (!client->IsDiscovering()) { NEARBY_LOGS(WARNING) << "Ignoring lost BluetoothDevice " << device.GetName() @@ -462,6 +474,12 @@ void P2pClusterPcpHandler::BluetoothNameChangedHandler( void P2pClusterPcpHandler::BluetoothDeviceLostHandler( ClientProxy* client, const std::string& service_id, BluetoothDevice& device) { + if (!device.IsValid()) { + NEARBY_LOGS(WARNING) + << "BluetoothDeviceLostHandler:Skipping the invalid Bluetooth device"; + return; + } + const std::string& device_name_string = device.GetName(); RunOnPcpHandlerThread( "p2p-bt-device-lost", [this, client, service_id,