1 // Copyright 2015 The Chromium Authors 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 <memory> 9 #include <vector> 10 11 #include <fuzzer/FuzzedDataProvider.h> 12 13 #include "base/files/file_path.h" 14 #include "base/logging.h" 15 #include "base/time/time.h" 16 #include "net/dns/dns_response.h" 17 #include "net/dns/record_parsed.h" 18 InitLogging()19void InitLogging() { 20 // For debugging, it may be helpful to enable verbose logging by setting the 21 // minimum log level to (-LOGGING_FATAL). 22 logging::SetMinLogLevel(logging::LOGGING_FATAL); 23 24 logging::LoggingSettings settings; 25 settings.logging_dest = 26 logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR; 27 logging::InitLogging(settings); 28 } 29 30 // Entry point for LibFuzzer. LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)31extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 32 InitLogging(); 33 34 FuzzedDataProvider data_provider(data, size); 35 size_t num_records = data_provider.ConsumeIntegral<size_t>(); 36 std::vector<uint8_t> packet = data_provider.ConsumeRemainingBytes<uint8_t>(); 37 38 net::DnsRecordParser parser(packet.data(), packet.size(), /*offset=*/0, 39 num_records); 40 if (!parser.IsValid()) { 41 return 0; 42 } 43 44 base::Time time; 45 std::unique_ptr<const net::RecordParsed> record_parsed; 46 do { 47 record_parsed = net::RecordParsed::CreateFrom(&parser, time); 48 } while (record_parsed); 49 50 net::DnsResourceRecord record; 51 while (parser.ReadRecord(&record)) { 52 } 53 54 return 0; 55 } 56