mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
Merge #18029: tests: Add fuzzing harness for AS-mapping (asmap)
4d2aceaad8tests: Add fuzzer asmap to FUZZERS_MISSING_CORPORA (temporarily) (practicalswift)8d07706985tests: Add fuzzing harness for AS-mapping (asmap) (practicalswift) Pull request description: Add fuzzing harness for AS-mapping (`asmap`). To test this PR: ``` $ make distclean $ ./autogen.sh $ CC=clang CXX=clang++ ./configure --enable-fuzz \ --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/asmap … ``` ACKs for top commit: MarcoFalke: ACK4d2aceaad8jonatack: ACK4d2aceaad8Tree-SHA512: bc4c63b48cd98c0cec9d10ecb43775b1bf1215241ff821fc7a866c7e2738605641fb88d044eabf2f48a8c16f2ced9ffce5165c9e6a83c73ece004350da7153e7
This commit is contained in:
28
src/test/fuzz/asmap.cpp
Normal file
28
src/test/fuzz/asmap.cpp
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user