1 // Copyright 2016 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 #ifdef UNSAFE_BUFFERS_BUILD 6 // TODO(crbug.com/40284755): Remove this and spanify to fix the errors. 7 #pragma allow_unsafe_buffers 8 #endif 9 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include <functional> 14 #include <string_view> 15 16 #include "net/base/address_list.h" 17 #include "net/base/ip_address.h" 18 19 // Entry point for LibFuzzer. LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)20extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 21 const std::string_view hostname(reinterpret_cast<const char*>(data), size); 22 net::IPAddress address; 23 24 if (net::ParseURLHostnameToAddress(hostname, &address)) { 25 // To fuzz port number without spending raw bytes of data, use hash(data). 26 std::size_t data_hash = std::hash<std::string>()(std::string(hostname)); 27 uint16_t port = static_cast<uint16_t>(data_hash & 0xFFFF); 28 net::AddressList addresses = 29 net::AddressList::CreateFromIPAddress(address, port); 30 31 for (const auto& endpoint : addresses) { 32 endpoint.ToString(); 33 } 34 } 35 36 return 0; 37 } 38