OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include <functional> |
| 9 |
| 10 #include "net/base/address_list.h" |
| 11 #include "net/base/ip_address.h" |
| 12 |
| 13 // Entry point for LibFuzzer. |
| 14 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 15 const base::StringPiece hostname(reinterpret_cast<const char*>(data), size); |
| 16 net::IPAddress address; |
| 17 |
| 18 if (net::ParseURLHostnameToAddress(hostname, &address)) { |
| 19 // To fuzz port number without spending raw bytes of data, use hash(data). |
| 20 std::size_t data_hash = std::hash<std::string>()(hostname.as_string()); |
| 21 uint16_t port = static_cast<uint16_t>(data_hash & 0xFFFF); |
| 22 net::AddressList addresses = |
| 23 net::AddressList::CreateFromIPAddress(address, port); |
| 24 |
| 25 for (const auto& endpoint : addresses) { |
| 26 endpoint.ToString(); |
| 27 } |
| 28 } |
| 29 |
| 30 return 0; |
| 31 } |
OLD | NEW |