mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
merge bitcoin#17050: Add fuzzing harnesses for functions parsing scripts, numbers, JSON and HD keypaths (bip32)
This commit is contained in:
parent
166232b6f3
commit
27d70d2fdf
@ -35,7 +35,11 @@ FUZZ_TARGETS = \
|
||||
test/fuzz/messageheader_deserialize \
|
||||
test/fuzz/netaddr_deserialize \
|
||||
test/fuzz/out_point_deserialize \
|
||||
test/fuzz/parse_hd_keypath \
|
||||
test/fuzz/parse_iso8601 \
|
||||
test/fuzz/parse_numbers \
|
||||
test/fuzz/parse_script \
|
||||
test/fuzz/parse_univalue \
|
||||
test/fuzz/partial_merkle_tree_deserialize \
|
||||
test/fuzz/partially_signed_transaction_deserialize \
|
||||
test/fuzz/prefilled_transaction_deserialize \
|
||||
@ -100,6 +104,7 @@ FUZZ_SUITE_LD_COMMON = \
|
||||
$(LIBBITCOIN_CONSENSUS) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBBITCOIN_WALLET) \
|
||||
$(LIBBITCOIN_CLI) \
|
||||
$(BDB_LIBS) \
|
||||
$(LIBUNIVALUE) \
|
||||
$(LIBLEVELDB) \
|
||||
@ -523,15 +528,39 @@ test_fuzz_tx_in_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_tx_in_SOURCES = $(FUZZ_SUITE) test/fuzz/tx_in.cpp
|
||||
test_fuzz_tx_in_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_tx_in_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_tx_in_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_tx_in_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
test_fuzz_tx_in_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
||||
test_fuzz_tx_out_SOURCES = $(FUZZ_SUITE) test/fuzz/tx_out.cpp
|
||||
test_fuzz_tx_out_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_tx_out_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_tx_out_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_tx_out_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
test_fuzz_tx_out_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
||||
test_fuzz_parse_hd_keypath_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_hd_keypath.cpp
|
||||
test_fuzz_parse_hd_keypath_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_parse_hd_keypath_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_parse_hd_keypath_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
test_fuzz_parse_hd_keypath_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
||||
test_fuzz_parse_script_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_script.cpp
|
||||
test_fuzz_parse_script_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_parse_script_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_parse_script_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
test_fuzz_parse_script_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
||||
test_fuzz_parse_numbers_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_numbers.cpp
|
||||
test_fuzz_parse_numbers_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_parse_numbers_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_parse_numbers_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
test_fuzz_parse_numbers_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
||||
test_fuzz_parse_univalue_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_univalue.cpp
|
||||
test_fuzz_parse_univalue_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_parse_univalue_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_parse_univalue_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
test_fuzz_parse_univalue_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
||||
endif # ENABLE_FUZZ
|
||||
|
||||
nodist_test_test_dash_SOURCES = $(GENERATED_TEST_FILES)
|
||||
|
13
src/test/fuzz/parse_hd_keypath.cpp
Normal file
13
src/test/fuzz/parse_hd_keypath.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2009-2019 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 <test/fuzz/fuzz.h>
|
||||
#include <util/bip32.h>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
const std::string keypath_str(buffer.begin(), buffer.end());
|
||||
std::vector<uint32_t> keypath;
|
||||
(void)ParseHDKeypath(keypath_str, keypath);
|
||||
}
|
35
src/test/fuzz/parse_numbers.cpp
Normal file
35
src/test/fuzz/parse_numbers.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2009-2019 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 <test/fuzz/fuzz.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
const std::string random_string(buffer.begin(), buffer.end());
|
||||
|
||||
CAmount amount;
|
||||
(void)ParseMoney(random_string, amount);
|
||||
|
||||
double d;
|
||||
(void)ParseDouble(random_string, &d);
|
||||
|
||||
int32_t i32;
|
||||
(void)ParseInt32(random_string, &i32);
|
||||
(void)atoi(random_string);
|
||||
|
||||
uint32_t u32;
|
||||
(void)ParseUInt32(random_string, &u32);
|
||||
|
||||
int64_t i64;
|
||||
(void)atoi64(random_string);
|
||||
(void)ParseFixedPoint(random_string, 3, &i64);
|
||||
(void)ParseInt64(random_string, &i64);
|
||||
|
||||
uint64_t u64;
|
||||
(void)ParseUInt64(random_string, &u64);
|
||||
}
|
16
src/test/fuzz/parse_script.cpp
Normal file
16
src/test/fuzz/parse_script.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2009-2019 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 <core_io.h>
|
||||
#include <script/script.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
const std::string script_string(buffer.begin(), buffer.end());
|
||||
try {
|
||||
(void)ParseScript(script_string);
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
}
|
87
src/test/fuzz/parse_univalue.cpp
Normal file
87
src/test/fuzz/parse_univalue.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2009-2019 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 <chainparams.h>
|
||||
#include <core_io.h>
|
||||
#include <key.h>
|
||||
#include <rpc/client.h>
|
||||
#include <rpc/util.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <util/memory.h>
|
||||
#include <script/sign.h>
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
void initialize()
|
||||
{
|
||||
static const auto verify_handle = MakeUnique<ECCVerifyHandle>();
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
}
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
const std::string random_string(buffer.begin(), buffer.end());
|
||||
bool valid = true;
|
||||
const UniValue univalue = [&] {
|
||||
try {
|
||||
return ParseNonRFCJSONValue(random_string);
|
||||
} catch (const std::runtime_error&) {
|
||||
valid = false;
|
||||
return NullUniValue;
|
||||
}
|
||||
}();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
(void)ParseHashO(univalue, "A");
|
||||
(void)ParseHashO(univalue, random_string);
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)ParseHashV(univalue, "A");
|
||||
(void)ParseHashV(univalue, random_string);
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)ParseHexO(univalue, "A");
|
||||
(void)ParseHexO(univalue, random_string);
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)ParseHexUV(univalue, "A");
|
||||
(void)ParseHexUV(univalue, random_string);
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)ParseHexV(univalue, "A");
|
||||
(void)ParseHexV(univalue, random_string);
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)ParseSighashString(univalue);
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)AmountFromValue(univalue);
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)ParseConfirmTarget(univalue, std::numeric_limits<unsigned int>::max());
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
try {
|
||||
(void)ParseDescriptorRange(univalue);
|
||||
} catch (const UniValue&) {
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
}
|
@ -26,6 +26,10 @@ FUZZERS_MISSING_CORPORA = [
|
||||
"locale",
|
||||
"merkle_block_deserialize",
|
||||
"out_point_deserialize",
|
||||
"parse_hd_keypath",
|
||||
"parse_numbers",
|
||||
"parse_script",
|
||||
"parse_univalue",
|
||||
"partial_merkle_tree_deserialize",
|
||||
"partially_signed_transaction_deserialize",
|
||||
"prefilled_transaction_deserialize",
|
||||
@ -34,8 +38,8 @@ FUZZERS_MISSING_CORPORA = [
|
||||
"pub_key_deserialize",
|
||||
"script_deserialize",
|
||||
"sub_net_deserialize",
|
||||
"tx_in_deserialize",
|
||||
"tx_in",
|
||||
"tx_in_deserialize",
|
||||
"tx_out",
|
||||
]
|
||||
|
||||
|
@ -17,6 +17,7 @@ KNOWN_VIOLATIONS=(
|
||||
"src/rpc/masternode.cpp.*atoi"
|
||||
"src/statsd_client.cpp:.*snprintf"
|
||||
"src/test/dbwrapper_tests.cpp:.*snprintf"
|
||||
"src/test/fuzz/parse_numbers.cpp:.*atoi"
|
||||
"src/torcontrol.cpp:.*atoi"
|
||||
"src/torcontrol.cpp:.*strtol"
|
||||
"src/util/strencodings.cpp:.*atoi"
|
||||
|
Loading…
Reference in New Issue
Block a user