Skip to content

Commit 554d89f

Browse files
committed
Merge #18029: tests: Add fuzzing harness for AS-mapping (asmap)
4d2acea tests: Add fuzzer asmap to FUZZERS_MISSING_CORPORA (temporarily) (practicalswift) 8d07706 tests: 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: ACK 4d2acea jonatack: ACK 4d2acea Tree-SHA512: bc4c63b48cd98c0cec9d10ecb43775b1bf1215241ff821fc7a866c7e2738605641fb88d044eabf2f48a8c16f2ced9ffce5165c9e6a83c73ece004350da7153e7
2 parents a064e00 + 4d2acea commit 554d89f

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FUZZ_TARGETS = \
77
test/fuzz/addr_info_deserialize \
88
test/fuzz/address_deserialize \
99
test/fuzz/addrman_deserialize \
10+
test/fuzz/asmap \
1011
test/fuzz/banentry_deserialize \
1112
test/fuzz/base_encode_decode \
1213
test/fuzz/bech32 \
@@ -255,6 +256,12 @@ test_fuzz_addrman_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
255256
test_fuzz_addrman_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
256257
test_fuzz_addrman_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
257258

259+
test_fuzz_asmap_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
260+
test_fuzz_asmap_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
261+
test_fuzz_asmap_LDADD = $(FUZZ_SUITE_LD_COMMON)
262+
test_fuzz_asmap_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
263+
test_fuzz_asmap_SOURCES = $(FUZZ_SUITE) test/fuzz/asmap.cpp
264+
258265
test_fuzz_banentry_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DBANENTRY_DESERIALIZE=1
259266
test_fuzz_banentry_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
260267
test_fuzz_banentry_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)

src/netaddress.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class CNetAddr
3939
explicit CNetAddr(const struct in_addr& ipv4Addr);
4040
void SetIP(const CNetAddr& ip);
4141

42-
private:
4342
/**
4443
* Set raw IPv4 or IPv6 address (in network byte order)
4544
* @note Only NET_IPV4 and NET_IPV6 are allowed for network.

src/test/fuzz/asmap.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <netaddress.h>
6+
#include <test/fuzz/FuzzedDataProvider.h>
7+
#include <test/fuzz/fuzz.h>
8+
9+
#include <cstdint>
10+
#include <vector>
11+
12+
void test_one_input(const std::vector<uint8_t>& buffer)
13+
{
14+
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
15+
const Network network = fuzzed_data_provider.PickValueInArray({NET_IPV4, NET_IPV6});
16+
if (fuzzed_data_provider.remaining_bytes() < 16) {
17+
return;
18+
}
19+
CNetAddr net_addr;
20+
net_addr.SetRaw(network, fuzzed_data_provider.ConsumeBytes<uint8_t>(16).data());
21+
std::vector<bool> asmap;
22+
for (const char cur_byte : fuzzed_data_provider.ConsumeRemainingBytes<char>()) {
23+
for (int bit = 0; bit < 8; ++bit) {
24+
asmap.push_back((cur_byte >> bit) & 1);
25+
}
26+
}
27+
(void)net_addr.GetMappedAS(asmap);
28+
}

test/fuzz/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Fuzzers known to lack a seed corpus in https://github.com/bitcoin-core/qa-assets/tree/master/fuzz_seed_corpus
1616
FUZZERS_MISSING_CORPORA = [
1717
"addr_info_deserialize",
18+
"asmap",
1819
"base_encode_decode",
1920
"block",
2021
"block_file_info_deserialize",

0 commit comments

Comments
 (0)