Commit effb01a5 authored by Jie Jiang's avatar Jie Jiang Committed by Commit Bot

arc: bluetooth: Check invalid handle in DeleteService

Since |service_handle| from Android might be invalid, we need an early
return instead of DCHECK().

BUG=b:147707738
TEST=When Fitbit is installed, no crash in cts test now.

Change-Id: Ia9aa8402960bb40457bd81a3d09b26a41aa27601
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2000401Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Jie Jiang <jiejiang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732684}
parent f4b612c5
......@@ -1918,11 +1918,16 @@ void ArcBluetoothBridge::StopService(int32_t service_handle,
void ArcBluetoothBridge::DeleteService(int32_t service_handle,
DeleteServiceCallback callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(gatt_identifier_.find(service_handle) != gatt_identifier_.end());
auto itr = gatt_identifier_.find(service_handle);
if (itr == gatt_identifier_.end()) {
LOG(WARNING) << "DeleteService called with invalid service handle.";
return;
}
BluetoothLocalGattService* service =
bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
bluetooth_adapter_->GetGattService(itr->second);
DCHECK(service);
gatt_identifier_.erase(service_handle);
gatt_identifier_.erase(itr);
gatt_handle_.erase(service->GetIdentifier());
service->Delete();
OnGattOperationDone(std::move(callback));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment