Chromium Code Reviews| 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 "base/json/json_writer.h" | |
| 9 #include "base/values.h" | |
| 10 #include "net/base/address_list.h" | |
| 11 #include "net/base/ip_address.h" | |
| 12 | |
| 13 static uint16_t CRC16(const uint8_t *data, const size_t size) { | |
| 14 static const uint16_t crctab[16] = { | |
| 15 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, | |
| 16 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, | |
| 17 }; | |
| 18 | |
| 19 uint16_t result = 0xffff; | |
| 20 for (size_t i = 0; i < size; i++) { | |
| 21 result = (result << 4) ^ crctab[(data[i] >> 4) ^ (result >> 12)]; | |
| 22 result = (result << 4) ^ crctab[(data[i] & 15) ^ (result >> 12)]; | |
| 23 } | |
| 24 | |
| 25 return result; | |
| 26 } | |
| 27 | |
| 28 // Entry point for LibFuzzer. | |
| 29 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
| 30 const base::StringPiece hostname(reinterpret_cast<const char*>(data), size); | |
| 31 net::IPAddress address; | |
| 32 | |
| 33 if (net::ParseURLHostnameToAddress(hostname, &address)) { | |
| 34 uint16_t port = CRC16(data, size); | |
|
eroman
2016/08/30 17:24:21
Please document why using a hash for the port (rat
aizatsky
2016/08/30 18:18:31
If don't need CRC16 specifically, I suggest you us
mmoroz
2016/08/31 11:18:24
Yes, exactly! Added a comment on that.
mmoroz
2016/08/31 11:18:24
Thanks for the suggestion. Done!
| |
| 35 net::AddressList addresses = net::AddressList::CreateFromIPAddress(address, | |
| 36 port); | |
| 37 base::ListValue endpoints; | |
| 38 for (auto endpoint : addresses) { | |
|
eroman
2016/08/30 17:24:21
nit: const auto&
mmoroz
2016/08/31 11:18:24
Done.
| |
| 39 endpoints.AppendString(endpoint.ToStringWithoutPort()); | |
| 40 } | |
| 41 | |
| 42 std::string json; | |
| 43 if (base::JSONWriter::Write(endpoints, &json)) { | |
|
eroman
2016/08/30 17:24:21
Why the dependency on constructing a base::Value a
aizatsky
2016/08/30 18:18:31
+1. Simply calling ToString on endpoint should be
mmoroz
2016/08/31 11:18:24
Done.
| |
| 44 return 0; | |
| 45 } | |
| 46 | |
| 47 return 0; | |
| 48 } | |
| 49 | |
| 50 return 0; | |
| 51 } | |
| OLD | NEW |