Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Unified Diff: components/arc/bluetooth/bluetooth_type_converters.cc

Issue 2046283003: Add unit test for ArcBluetoothBridge and TypeConverter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt
Patch Set: Range check in type_converters Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 =

Powered by Google App Engine
This is Rietveld 408576698