Add size limit check for Bluetooth Classic SetName

PiperOrigin-RevId: 455442872
This commit is contained in:
aaronyujiaze
2022-06-16 12:34:35 -07:00
committed by Copybara-Service
parent 320d4437ca
commit 6bd1a78eeb
@@ -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()) {