From 6bd1a78eebd571aa9a35a993d90f1b6018b18e9a Mon Sep 17 00:00:00 2001 From: aaronyujiaze Date: Thu, 16 Jun 2022 12:32:45 -0700 Subject: [PATCH] Add size limit check for Bluetooth Classic SetName PiperOrigin-RevId: 455442872 --- .../platform/implementation/windows/bluetooth_adapter.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/platform/implementation/windows/bluetooth_adapter.cc b/internal/platform/implementation/windows/bluetooth_adapter.cc index cffe1662..8925f032 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter.cc +++ b/internal/platform/implementation/windows/bluetooth_adapter.cc @@ -246,6 +246,13 @@ std::string BluetoothAdapter::GetName() const { // https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#setName(java.lang.String) bool BluetoothAdapter::SetName(absl::string_view name) { + if (name.size() > 70 * sizeof(char)) { + NEARBY_LOGS(ERROR) << __func__ + << ": Failed to set name for bluetooth adapter because " + "the name exceeded the 70 bytes limit for Windows."; + return false; + } + std::string instance_id(GetGenericBluetoothAdapterInstanceID()); if (instance_id.empty()) {