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

Unified Diff: device/u2f/u2f_hid_device.cc

Issue 2771673002: Use vectors instead of IOBuffer for U2fPackets (Closed)
Patch Set: Modify fuzzer Created 3 years, 9 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
« no previous file with comments | « no previous file | device/u2f/u2f_message.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/u2f/u2f_hid_device.cc
diff --git a/device/u2f/u2f_hid_device.cc b/device/u2f/u2f_hid_device.cc
index 7bebafb1a458dfa4eeb6eba6235e9b95d408cfdc..c313b96e4c165aab270e68e616c552fa4401d62c 100644
--- a/device/u2f/u2f_hid_device.cc
+++ b/device/u2f/u2f_hid_device.cc
@@ -197,15 +197,14 @@ void U2fHidDevice::OnRead(U2fHidMessageCallback callback,
bool success,
scoped_refptr<net::IOBuffer> buf,
size_t size) {
- if (!success) {
+ if (!success || !buf) {
std::move(callback).Run(success, nullptr);
return;
}
- scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(size));
- memcpy(buffer->data(), buf->data(), size);
+ std::vector<uint8_t> read_buffer(buf->data(), buf->data() + size);
std::unique_ptr<U2fMessage> read_message =
- U2fMessage::CreateFromSerializedData(buffer);
+ U2fMessage::CreateFromSerializedData(read_buffer);
if (!read_message) {
std::move(callback).Run(false, nullptr);
@@ -236,14 +235,13 @@ void U2fHidDevice::OnReadContinuation(std::unique_ptr<U2fMessage> message,
bool success,
scoped_refptr<net::IOBuffer> buf,
size_t size) {
- if (!success) {
+ if (!success || !buf) {
std::move(callback).Run(success, nullptr);
return;
}
- scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(size));
- memcpy(buffer->data(), buf->data(), size);
- message->AddContinuationPacket(buffer);
+ std::vector<uint8_t> read_buffer(buf->data(), buf->data() + size);
+ message->AddContinuationPacket(read_buffer);
if (message->MessageComplete()) {
std::move(callback).Run(success, std::move(message));
return;
« no previous file with comments | « no previous file | device/u2f/u2f_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698