Index: components/arc/bluetooth/bluetooth_type_converters.cc |
diff --git a/components/arc/bluetooth/bluetooth_type_converters.cc b/components/arc/bluetooth/bluetooth_type_converters.cc |
index af2e08b33ca1f97508d528d0c968156dc09906fb..f91139d0434d9b248e64f0b3e9456cfd2ea3c44a 100644 |
--- a/components/arc/bluetooth/bluetooth_type_converters.cc |
+++ b/components/arc/bluetooth/bluetooth_type_converters.cc |
@@ -19,6 +19,10 @@ |
namespace { |
+constexpr size_t kAddressSize = 6; |
+constexpr size_t kUUIDSize = 16; |
+constexpr char kInvalidAddress[] = "00:00:00:00:00:00"; |
+ |
bool IsNonHex(char c) { |
return !isxdigit(c); |
} |
@@ -35,8 +39,6 @@ std::string StripNonHex(const std::string& str) { |
namespace mojo { |
-// TODO(smbarber): Add unit tests for Bluetooth type converters. |
- |
// static |
arc::mojom::BluetoothAddressPtr |
TypeConverter<arc::mojom::BluetoothAddressPtr, std::string>::Convert( |
@@ -61,6 +63,9 @@ std::string TypeConverter<std::string, arc::mojom::BluetoothAddress>::Convert( |
const mojo::Array<uint8_t>& bytes = address.address; |
+ if (address.address.size() != kAddressSize) |
+ return std::string(kInvalidAddress); |
+ |
for (size_t k = 0; k < bytes.size(); k++) { |
addr_stream << std::setw(2) << (unsigned int)bytes[k]; |
addr_stream << ((k == bytes.size() - 1) ? "" : ":"); |
@@ -90,6 +95,9 @@ TypeConverter<device::BluetoothUUID, arc::mojom::BluetoothUUIDPtr>::Convert( |
const arc::mojom::BluetoothUUIDPtr& uuid) { |
std::vector<uint8_t> address_bytes = uuid->uuid.To<std::vector<uint8_t>>(); |
+ if (address_bytes.size() != kUUIDSize) |
+ return device::BluetoothUUID(); |
+ |
// BluetoothUUID expects the format below with the dashes inserted. |
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
std::string uuid_str = |