Skip to content

Commit fb8c120

Browse files
tests: Add ParseScript(...) (core_io) fuzzing harness
1 parent 074cb64 commit fb8c120

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ FUZZ_TARGETS = \
3838
test/fuzz/partial_merkle_tree_deserialize \
3939
test/fuzz/partially_signed_transaction_deserialize \
4040
test/fuzz/prefilled_transaction_deserialize \
41+
test/fuzz/parse_script \
4142
test/fuzz/psbt \
4243
test/fuzz/psbt_input_deserialize \
4344
test/fuzz/psbt_output_deserialize \
@@ -525,6 +526,12 @@ test_fuzz_parse_hd_keypath_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
525526
test_fuzz_parse_hd_keypath_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
526527
test_fuzz_parse_hd_keypath_LDADD = $(FUZZ_SUITE_LD_COMMON)
527528

529+
test_fuzz_parse_script_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_script.cpp
530+
test_fuzz_parse_script_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
531+
test_fuzz_parse_script_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
532+
test_fuzz_parse_script_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
533+
test_fuzz_parse_script_LDADD = $(FUZZ_SUITE_LD_COMMON)
534+
528535
endif # ENABLE_FUZZ
529536

530537
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)

src/test/fuzz/parse_script.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2009-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 <core_io.h>
6+
#include <script/script.h>
7+
#include <test/fuzz/fuzz.h>
8+
9+
void test_one_input(const std::vector<uint8_t>& buffer)
10+
{
11+
const std::string script_string(buffer.begin(), buffer.end());
12+
try {
13+
(void)ParseScript(script_string);
14+
} catch (const std::runtime_error&) {
15+
}
16+
}

0 commit comments

Comments
 (0)