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 3 // found in the LICENSE file. 4 5 #include <stddef.h> 6 #include <stdint.h> 7 8 #include <fuzzer/FuzzedDataProvider.h> 9 10 #include <vector> 11 12 #include "net/websockets/websocket_frame_parser.h" 13 14 // Entry point for LibFuzzer. LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)15extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 16 FuzzedDataProvider fuzzed_data_provider(data, size); 17 net::WebSocketFrameParser parser; 18 std::vector<std::unique_ptr<net::WebSocketFrameChunk>> frame_chunks; 19 while (fuzzed_data_provider.remaining_bytes() > 0) { 20 size_t chunk_size = fuzzed_data_provider.ConsumeIntegralInRange(1, 32); 21 std::vector<char> chunk = 22 fuzzed_data_provider.ConsumeBytes<char>(chunk_size); 23 parser.Decode(chunk.data(), chunk.size(), &frame_chunks); 24 } 25 return 0; 26 } 27