Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/bluetooth_uuid.h" | 5 #include "device/bluetooth/bluetooth_uuid.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "ipc/ipc_message.h" | |
| 10 | 11 |
| 11 namespace device { | 12 namespace device { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb"; | 16 const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb"; |
| 16 const char* kCommonUuidPrefix = "0000"; | 17 const char* kCommonUuidPrefix = "0000"; |
| 17 | 18 |
| 18 // Returns the canonical, 128-bit canonical, and the format of the UUID | 19 // Returns the canonical, 128-bit canonical, and the format of the UUID |
| 19 // in |canonical|, |canonical_128|, and |format| based on |uuid|. | 20 // in |canonical|, |canonical_128|, and |format| based on |uuid|. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 87 |
| 87 bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const { | 88 bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const { |
| 88 return canonical_value_ != uuid.canonical_value_; | 89 return canonical_value_ != uuid.canonical_value_; |
| 89 } | 90 } |
| 90 | 91 |
| 91 void PrintTo(const BluetoothUUID& uuid, std::ostream* out) { | 92 void PrintTo(const BluetoothUUID& uuid, std::ostream* out) { |
| 92 *out << uuid.canonical_value(); | 93 *out << uuid.canonical_value(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 } // namespace device | 96 } // namespace device |
| 97 | |
| 98 void IPC::ParamTraits<device::BluetoothUUID>::Write(Message* m, | |
| 99 const param_type& p) { | |
| 100 m->WriteString(p.canonical_value()); | |
| 101 } | |
| 102 | |
| 103 bool IPC::ParamTraits<device::BluetoothUUID>::Read(const Message* m, | |
| 104 base::PickleIterator* iter, | |
| 105 param_type* r) { | |
| 106 std::string value; | |
| 107 if (!iter->ReadString(&value)) | |
| 108 return false; | |
| 109 *r = device::BluetoothUUID(value); | |
| 110 // If the format isn't 128-bit, .value() would return a different answer than | |
| 111 // .canonical_value(). Then if browser-side code accidentally checks .value() | |
| 112 // against a 128-bit string literal, a hostile renderer could use the 16- or | |
| 113 // 32-bit format and evade the check. | |
| 114 return r->format() == device::BluetoothUUID::kFormat128Bit; | |
|
armansito
2015/06/23 18:24:28
I'm not fully understanding the necessity for this
scheib
2015/06/23 18:33:27
A correctly running renderer will construct a 128b
Jeffrey Yasskin
2015/06/24 21:04:25
Yeah, we could recover from a non-128-bit message
armansito
2015/06/24 21:26:43
Got it. If that's the consensus on what the IPC be
| |
| 115 } | |
| 116 | |
| 117 void IPC::ParamTraits<device::BluetoothUUID>::Log(const param_type& p, | |
| 118 std::string* l) { | |
| 119 l->append(p.canonical_value()); | |
| 120 } | |
| OLD | NEW |