mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
tests: Add fuzzing harnesses for various number parsing functions
This commit is contained in:
parent
fb8c12093a
commit
e3d2bcf5cf
@ -38,6 +38,7 @@ FUZZ_TARGETS = \
|
||||
test/fuzz/partial_merkle_tree_deserialize \
|
||||
test/fuzz/partially_signed_transaction_deserialize \
|
||||
test/fuzz/prefilled_transaction_deserialize \
|
||||
test/fuzz/parse_numbers \
|
||||
test/fuzz/parse_script \
|
||||
test/fuzz/psbt \
|
||||
test/fuzz/psbt_input_deserialize \
|
||||
@ -532,6 +533,12 @@ test_fuzz_parse_script_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_parse_script_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
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)
|
||||
test_fuzz_parse_numbers_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
||||
endif # ENABLE_FUZZ
|
||||
|
||||
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
|
||||
|
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);
|
||||
}
|
@ -11,6 +11,7 @@ KNOWN_VIOLATIONS=(
|
||||
"src/qt/rpcconsole.cpp:.*atoi"
|
||||
"src/rest.cpp:.*strtol"
|
||||
"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