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

Side by Side Diff: net/websockets/websocket_deflate_stream_fuzzer.cc

Issue 2308443002: Make FuzzedDataProvider vend std::strings (Closed)
Patch Set: thestig review Created 4 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 auto frame = base::MakeUnique<WebSocketFrame>(opcode); 60 auto frame = base::MakeUnique<WebSocketFrame>(opcode);
61 // Bad news: ConsumeBool actually consumes a whole byte per call, so do 61 // Bad news: ConsumeBool actually consumes a whole byte per call, so do
62 // something hacky to conserve precious bits. 62 // something hacky to conserve precious bits.
63 uint8_t flags = fuzzed_data_provider_.ConsumeUint8(); 63 uint8_t flags = fuzzed_data_provider_.ConsumeUint8();
64 frame->header.final = flags & 0x1; 64 frame->header.final = flags & 0x1;
65 frame->header.reserved1 = (flags >> 1) & 0x1; 65 frame->header.reserved1 = (flags >> 1) & 0x1;
66 frame->header.reserved2 = (flags >> 2) & 0x1; 66 frame->header.reserved2 = (flags >> 2) & 0x1;
67 frame->header.reserved3 = (flags >> 3) & 0x1; 67 frame->header.reserved3 = (flags >> 3) & 0x1;
68 frame->header.masked = (flags >> 4) & 0x1; 68 frame->header.masked = (flags >> 4) & 0x1;
69 uint64_t payload_length = fuzzed_data_provider_.ConsumeInt32InRange(0, 64); 69 uint64_t payload_length = fuzzed_data_provider_.ConsumeInt32InRange(0, 64);
70 base::StringPiece payload = 70 std::string payload = fuzzed_data_provider_.ConsumeBytes(payload_length);
71 fuzzed_data_provider_.ConsumeBytes(payload_length); 71 frame->data = new StringIOBuffer(payload);
72 frame->data = new WrappedIOBuffer(payload.data());
73 frame->header.payload_length = payload.size(); 72 frame->header.payload_length = payload.size();
74 return frame; 73 return frame;
75 } 74 }
76 75
77 base::FuzzedDataProvider fuzzed_data_provider_; 76 base::FuzzedDataProvider fuzzed_data_provider_;
78 }; 77 };
79 78
80 void WebSocketDeflateStreamFuzz(const uint8_t* data, size_t size) { 79 void WebSocketDeflateStreamFuzz(const uint8_t* data, size_t size) {
81 // WebSocketDeflateStream needs to be constructed on each call because it 80 // WebSocketDeflateStream needs to be constructed on each call because it
82 // has state. 81 // has state.
(...skipping 11 matching lines...) Expand all
94 } // namespace 93 } // namespace
95 94
96 } // namespace net 95 } // namespace net
97 96
98 // Entry point for LibFuzzer. 97 // Entry point for LibFuzzer.
99 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 98 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
100 net::WebSocketDeflateStreamFuzz(data, size); 99 net::WebSocketDeflateStreamFuzz(data, size);
101 100
102 return 0; 101 return 0;
103 } 102 }
OLDNEW
« no previous file with comments | « net/url_request/url_request_data_job_fuzzer.cc ('k') | net/websockets/websocket_frame_parser_fuzzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698