Skip to content

Commit

Permalink
tests: Add fuzzing harness for LoadMempool(...) and DumpMempool(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift committed Jul 11, 2020
1 parent 0043325 commit 80a379a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Makefile.test.include
Expand Up @@ -139,7 +139,8 @@ FUZZ_TARGETS = \
test/fuzz/txoutcompressor_deserialize \
test/fuzz/txundo_deserialize \
test/fuzz/uint160_deserialize \
test/fuzz/uint256_deserialize
test/fuzz/uint256_deserialize \
test/fuzz/validation_load_mempool

if ENABLE_FUZZ
noinst_PROGRAMS += $(FUZZ_TARGETS:=)
Expand Down Expand Up @@ -1130,6 +1131,12 @@ test_fuzz_uint256_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_uint256_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
test_fuzz_uint256_deserialize_SOURCES = test/fuzz/deserialize.cpp

test_fuzz_validation_load_mempool_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
test_fuzz_validation_load_mempool_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_validation_load_mempool_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_validation_load_mempool_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
test_fuzz_validation_load_mempool_SOURCES = test/fuzz/validation_load_mempool.cpp

endif # ENABLE_FUZZ

nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
Expand Down
41 changes: 41 additions & 0 deletions src/test/fuzz/validation_load_mempool.cpp
@@ -0,0 +1,41 @@
// 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 <chainparamsbase.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <validation.h>

#include <cstdint>
#include <vector>

namespace {
FuzzedFileProvider* fuzzed_file_provider_ptr = nullptr;

FILE* fuzzed_fopen(const fs::path&, const char*)
{
return fuzzed_file_provider_ptr->open();
}
} // namespace

void initialize()
{
static TestingSetup setup{CBaseChainParams::REGTEST, {"-nodebuglogfile"}};
}

void test_one_input(const std::vector<uint8_t>& buffer)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
fuzzed_file_provider_ptr = &fuzzed_file_provider;

CTxMemPool pool;
(void)LoadMempool(pool, fuzzed_fopen);
(void)DumpMempool(pool, fuzzed_fopen, true);

fuzzed_file_provider_ptr = nullptr;
}

0 comments on commit 80a379a

Please sign in to comment.