diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2020-01-30 16:04:25 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2020-01-30 16:04:38 +0000 |
commit | 8d07706985a72b105b63efa289121d17d31607a1 (patch) | |
tree | 5f1d7b8955a9e23dbadb214b56ecbb2f01024a03 /src/test/fuzz/asmap.cpp | |
parent | 7fcaa8291c6e155e6f5fba42e2ee8ec0bee046a3 (diff) |
tests: Add fuzzing harness for AS-mapping (asmap)
Diffstat (limited to 'src/test/fuzz/asmap.cpp')
-rw-r--r-- | src/test/fuzz/asmap.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/fuzz/asmap.cpp b/src/test/fuzz/asmap.cpp new file mode 100644 index 0000000000..7f3eef79a1 --- /dev/null +++ b/src/test/fuzz/asmap.cpp @@ -0,0 +1,28 @@ +// Copyright (c) 2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <netaddress.h> +#include <test/fuzz/FuzzedDataProvider.h> +#include <test/fuzz/fuzz.h> + +#include <cstdint> +#include <vector> + +void test_one_input(const std::vector<uint8_t>& buffer) +{ + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); + const Network network = fuzzed_data_provider.PickValueInArray({NET_IPV4, NET_IPV6}); + if (fuzzed_data_provider.remaining_bytes() < 16) { + return; + } + CNetAddr net_addr; + net_addr.SetRaw(network, fuzzed_data_provider.ConsumeBytes<uint8_t>(16).data()); + std::vector<bool> asmap; + for (const char cur_byte : fuzzed_data_provider.ConsumeRemainingBytes<char>()) { + for (int bit = 0; bit < 8; ++bit) { + asmap.push_back((cur_byte >> bit) & 1); + } + } + (void)net_addr.GetMappedAS(asmap); +} |