Skip to content

Commit ce93529

Browse files
tests: Add fuzzing harness for various CTxIn related functions
1 parent cb11324 commit ce93529

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ FUZZ_TARGETS = \
4747
test/fuzz/spanparsing \
4848
test/fuzz/sub_net_deserialize \
4949
test/fuzz/transaction \
50+
test/fuzz/tx_in \
5051
test/fuzz/tx_in_deserialize \
5152
test/fuzz/txoutcompressor_deserialize \
5253
test/fuzz/txundo_deserialize
@@ -497,6 +498,12 @@ test_fuzz_tx_in_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
497498
test_fuzz_tx_in_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
498499
test_fuzz_tx_in_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
499500

501+
test_fuzz_tx_in_SOURCES = $(FUZZ_SUITE) test/fuzz/tx_in.cpp
502+
test_fuzz_tx_in_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
503+
test_fuzz_tx_in_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
504+
test_fuzz_tx_in_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
505+
test_fuzz_tx_in_LDADD = $(FUZZ_SUITE_LD_COMMON)
506+
500507
endif # ENABLE_FUZZ
501508

502509
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)

src/test/fuzz/tx_in.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2019 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 <consensus/validation.h>
6+
#include <core_memusage.h>
7+
#include <policy/policy.h>
8+
#include <primitives/transaction.h>
9+
#include <streams.h>
10+
#include <test/fuzz/fuzz.h>
11+
#include <version.h>
12+
13+
#include <cassert>
14+
15+
void test_one_input(const std::vector<uint8_t>& buffer)
16+
{
17+
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
18+
CTxIn tx_in;
19+
try {
20+
int version;
21+
ds >> version;
22+
ds.SetVersion(version);
23+
ds >> tx_in;
24+
} catch (const std::ios_base::failure&) {
25+
return;
26+
}
27+
28+
(void)GetTransactionInputWeight(tx_in);
29+
(void)GetVirtualTransactionInputSize(tx_in);
30+
(void)RecursiveDynamicUsage(tx_in);
31+
32+
(void)tx_in.ToString();
33+
}

0 commit comments

Comments
 (0)