File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
FUZZ_TARGETS = \
6
6
test/fuzz/addr_info_deserialize \
7
+ test/fuzz/addrdb \
7
8
test/fuzz/address_deserialize \
8
9
test/fuzz/addrman_deserialize \
9
10
test/fuzz/asmap \
@@ -288,6 +289,12 @@ test_fuzz_addr_info_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
288
289
test_fuzz_addr_info_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
289
290
test_fuzz_addr_info_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
290
291
292
+ test_fuzz_addrdb_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
293
+ test_fuzz_addrdb_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
294
+ test_fuzz_addrdb_LDADD = $(FUZZ_SUITE_LD_COMMON)
295
+ test_fuzz_addrdb_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
296
+ test_fuzz_addrdb_SOURCES = $(FUZZ_SUITE) test/fuzz/addrdb.cpp
297
+
291
298
test_fuzz_address_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DADDRESS_DESERIALIZE=1
292
299
test_fuzz_address_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
293
300
test_fuzz_address_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
Original file line number Diff line number Diff line change
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 < addrdb.h>
6
+ #include < optional.h>
7
+ #include < test/fuzz/FuzzedDataProvider.h>
8
+ #include < test/fuzz/fuzz.h>
9
+ #include < test/fuzz/util.h>
10
+
11
+ #include < cassert>
12
+ #include < cstdint>
13
+ #include < string>
14
+ #include < vector>
15
+
16
+ void test_one_input (const std::vector<uint8_t >& buffer)
17
+ {
18
+ FuzzedDataProvider fuzzed_data_provider (buffer.data (), buffer.size ());
19
+
20
+ const CBanEntry ban_entry = [&] {
21
+ switch (fuzzed_data_provider.ConsumeIntegralInRange <int >(0 , 3 )) {
22
+ case 0 :
23
+ return CBanEntry{fuzzed_data_provider.ConsumeIntegral <int64_t >()};
24
+ break ;
25
+ case 1 :
26
+ return CBanEntry{fuzzed_data_provider.ConsumeIntegral <int64_t >(), fuzzed_data_provider.PickValueInArray <BanReason>({
27
+ BanReason::BanReasonUnknown,
28
+ BanReason::BanReasonNodeMisbehaving,
29
+ BanReason::BanReasonManuallyAdded,
30
+ })};
31
+ break ;
32
+ case 2 : {
33
+ const Optional<CBanEntry> ban_entry = ConsumeDeserializable<CBanEntry>(fuzzed_data_provider);
34
+ if (ban_entry) {
35
+ return *ban_entry;
36
+ }
37
+ break ;
38
+ }
39
+ }
40
+ return CBanEntry{};
41
+ }();
42
+ assert (!ban_entry.banReasonToString ().empty ());
43
+ }
You can’t perform that action at this time.
0 commit comments