Skip to content

Commit 103b6ec

Browse files
tests: Add fuzzing coverage for TransactionErrorString(...)
1 parent dde508b commit 103b6ec

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ FUZZ_TARGETS = \
4949
test/fuzz/key \
5050
test/fuzz/key_io \
5151
test/fuzz/key_origin_info_deserialize \
52+
test/fuzz/kitchen_sink \
5253
test/fuzz/locale \
5354
test/fuzz/merkle_block_deserialize \
5455
test/fuzz/merkleblock \
@@ -568,6 +569,12 @@ test_fuzz_key_origin_info_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
568569
test_fuzz_key_origin_info_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
569570
test_fuzz_key_origin_info_deserialize_SOURCES = test/fuzz/deserialize.cpp
570571

572+
test_fuzz_kitchen_sink_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
573+
test_fuzz_kitchen_sink_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
574+
test_fuzz_kitchen_sink_LDADD = $(FUZZ_SUITE_LD_COMMON)
575+
test_fuzz_kitchen_sink_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
576+
test_fuzz_kitchen_sink_SOURCES = test/fuzz/kitchen_sink.cpp
577+
571578
test_fuzz_locale_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
572579
test_fuzz_locale_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
573580
test_fuzz_locale_LDADD = $(FUZZ_SUITE_LD_COMMON)

src/test/fuzz/kitchen_sink.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 <test/fuzz/FuzzedDataProvider.h>
6+
#include <test/fuzz/fuzz.h>
7+
#include <test/fuzz/util.h>
8+
#include <util/error.h>
9+
10+
#include <cstdint>
11+
#include <vector>
12+
13+
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
14+
// fuzzed but a.) don't belong in any existing fuzzing harness file, and
15+
// b.) are not important enough to warrant their own fuzzing harness file.
16+
void test_one_input(const std::vector<uint8_t>& buffer)
17+
{
18+
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19+
20+
const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray<TransactionError>({TransactionError::OK, TransactionError::MISSING_INPUTS, TransactionError::ALREADY_IN_CHAIN, TransactionError::P2P_DISABLED, TransactionError::MEMPOOL_REJECTED, TransactionError::MEMPOOL_ERROR, TransactionError::INVALID_PSBT, TransactionError::PSBT_MISMATCH, TransactionError::SIGHASH_MISMATCH, TransactionError::MAX_FEE_EXCEEDED});
21+
(void)TransactionErrorString(transaction_error);
22+
}

0 commit comments

Comments
 (0)