Skip to content

Commit 9718f38

Browse files
tests: Add fuzzing harness for functions/classes in merkleblock.h
1 parent a16ea05 commit 9718f38

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ FUZZ_TARGETS = \
4545
test/fuzz/key_origin_info_deserialize \
4646
test/fuzz/locale \
4747
test/fuzz/merkle_block_deserialize \
48+
test/fuzz/merkleblock \
4849
test/fuzz/messageheader_deserialize \
4950
test/fuzz/multiplication_overflow \
5051
test/fuzz/net_permissions \
@@ -541,6 +542,12 @@ test_fuzz_merkle_block_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
541542
test_fuzz_merkle_block_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
542543
test_fuzz_merkle_block_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
543544

545+
test_fuzz_merkleblock_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
546+
test_fuzz_merkleblock_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
547+
test_fuzz_merkleblock_LDADD = $(FUZZ_SUITE_LD_COMMON)
548+
test_fuzz_merkleblock_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
549+
test_fuzz_merkleblock_SOURCES = $(FUZZ_SUITE) test/fuzz/merkleblock.cpp
550+
544551
test_fuzz_messageheader_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DMESSAGEHEADER_DESERIALIZE=1
545552
test_fuzz_messageheader_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
546553
test_fuzz_messageheader_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)

src/test/fuzz/merkleblock.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 <merkleblock.h>
6+
#include <optional.h>
7+
#include <test/fuzz/FuzzedDataProvider.h>
8+
#include <test/fuzz/fuzz.h>
9+
#include <test/fuzz/util.h>
10+
#include <uint256.h>
11+
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+
Optional<CPartialMerkleTree> partial_merkle_tree = ConsumeDeserializable<CPartialMerkleTree>(fuzzed_data_provider);
20+
if (!partial_merkle_tree) {
21+
return;
22+
}
23+
(void)partial_merkle_tree->GetNumTransactions();
24+
std::vector<uint256> matches;
25+
std::vector<unsigned int> indices;
26+
(void)partial_merkle_tree->ExtractMatches(matches, indices);
27+
}

0 commit comments

Comments
 (0)