aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-02-05 11:38:04 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-02-05 11:40:22 +0100
commit554d89fb295efe5c8adc81583d5ded1acbd98305 (patch)
tree739e4c164b2d6b60e7efc7ae6d6d12582bf743e3 /src/test
parenta064e005fa6b2b9f2c7f01e45a04a4d740f4605d (diff)
parent4d2aceaad8d28a54246b6639966e2278d2d795e3 (diff)
downloadbitcoin-554d89fb295efe5c8adc81583d5ded1acbd98305.tar.xz
Merge #18029: tests: Add fuzzing harness for AS-mapping (asmap)
4d2aceaad8d28a54246b6639966e2278d2d795e3 tests: Add fuzzer asmap to FUZZERS_MISSING_CORPORA (temporarily) (practicalswift) 8d07706985a72b105b63efa289121d17d31607a1 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 4d2aceaad8d28a54246b6639966e2278d2d795e3 jonatack: ACK 4d2aceaad8d28a54246b6639966e2278d2d795e3 Tree-SHA512: bc4c63b48cd98c0cec9d10ecb43775b1bf1215241ff821fc7a866c7e2738605641fb88d044eabf2f48a8c16f2ced9ffce5165c9e6a83c73ece004350da7153e7
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/asmap.cpp28
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);
+}