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

Side by Side Diff: device/u2f/u2f_message_fuzzer.cc

Issue 2766723003: Use unique pointers for U2fPacket and U2fMessage (Closed)
Patch Set: Change fuzzer to use the new unique_ptr constructor 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 unified diff | Download patch
« no previous file with comments | « device/u2f/u2f_message.cc ('k') | device/u2f/u2f_message_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <algorithm> 7 #include <algorithm>
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "u2f_message.h" 9 #include "u2f_message.h"
10 10
11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12 size_t packet_size = 65; 12 size_t packet_size = 65;
13 size_t remaining_buffer = size; 13 size_t remaining_buffer = size;
14 uint8_t* start = const_cast<uint8_t*>(data); 14 uint8_t* start = const_cast<uint8_t*>(data);
15 15
16 scoped_refptr<net::IOBufferWithSize> buf( 16 scoped_refptr<net::IOBufferWithSize> buf(
17 new net::IOBufferWithSize(packet_size)); 17 new net::IOBufferWithSize(packet_size));
18 memcpy(buf->data(), start, std::min(packet_size, remaining_buffer)); 18 memcpy(buf->data(), start, std::min(packet_size, remaining_buffer));
19 scoped_refptr<device::U2fMessage> msg = 19 std::unique_ptr<device::U2fMessage> msg =
20 device::U2fMessage::CreateFromSerializedData(buf); 20 device::U2fMessage::CreateFromSerializedData(buf);
21 21
22 remaining_buffer -= std::min(remaining_buffer, packet_size); 22 remaining_buffer -= std::min(remaining_buffer, packet_size);
23 start += packet_size; 23 start += packet_size;
24 24
25 while (remaining_buffer > 0) { 25 while (remaining_buffer > 0) {
26 size_t buffer_size = std::min(packet_size, remaining_buffer); 26 size_t buffer_size = std::min(packet_size, remaining_buffer);
27 scoped_refptr<net::IOBufferWithSize> tmp_buf( 27 scoped_refptr<net::IOBufferWithSize> tmp_buf(
28 new net::IOBufferWithSize(buffer_size)); 28 new net::IOBufferWithSize(buffer_size));
29 memcpy(tmp_buf->data(), start, buffer_size); 29 memcpy(tmp_buf->data(), start, buffer_size);
30 msg->AddContinuationPacket(tmp_buf); 30 msg->AddContinuationPacket(tmp_buf);
31 remaining_buffer -= std::min(remaining_buffer, buffer_size); 31 remaining_buffer -= std::min(remaining_buffer, buffer_size);
32 start += buffer_size; 32 start += buffer_size;
33 } 33 }
34 34
35 return 0; 35 return 0;
36 } 36 }
OLDNEW
« no previous file with comments | « device/u2f/u2f_message.cc ('k') | device/u2f/u2f_message_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698