Skip to content

Commit e3d2bcf

Browse files
tests: Add fuzzing harnesses for various number parsing functions
1 parent fb8c120 commit e3d2bcf

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-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_numbers \
4142
test/fuzz/parse_script \
4243
test/fuzz/psbt \
4344
test/fuzz/psbt_input_deserialize \
@@ -532,6 +533,12 @@ test_fuzz_parse_script_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
532533
test_fuzz_parse_script_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
533534
test_fuzz_parse_script_LDADD = $(FUZZ_SUITE_LD_COMMON)
534535

536+
test_fuzz_parse_numbers_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_numbers.cpp
537+
test_fuzz_parse_numbers_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
538+
test_fuzz_parse_numbers_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
539+
test_fuzz_parse_numbers_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
540+
test_fuzz_parse_numbers_LDADD = $(FUZZ_SUITE_LD_COMMON)
541+
535542
endif # ENABLE_FUZZ
536543

537544
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)

src/test/fuzz/parse_numbers.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 <test/fuzz/fuzz.h>
6+
#include <util/moneystr.h>
7+
#include <util/strencodings.h>
8+
9+
#include <string>
10+
11+
void test_one_input(const std::vector<uint8_t>& buffer)
12+
{
13+
const std::string random_string(buffer.begin(), buffer.end());
14+
15+
CAmount amount;
16+
(void)ParseMoney(random_string, amount);
17+
18+
double d;
19+
(void)ParseDouble(random_string, &d);
20+
21+
int32_t i32;
22+
(void)ParseInt32(random_string, &i32);
23+
(void)atoi(random_string);
24+
25+
uint32_t u32;
26+
(void)ParseUInt32(random_string, &u32);
27+
28+
int64_t i64;
29+
(void)atoi64(random_string);
30+
(void)ParseFixedPoint(random_string, 3, &i64);
31+
(void)ParseInt64(random_string, &i64);
32+
33+
uint64_t u64;
34+
(void)ParseUInt64(random_string, &u64);
35+
}

test/lint/lint-locale-dependence.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ KNOWN_VIOLATIONS=(
1111
"src/qt/rpcconsole.cpp:.*atoi"
1212
"src/rest.cpp:.*strtol"
1313
"src/test/dbwrapper_tests.cpp:.*snprintf"
14+
"src/test/fuzz/parse_numbers.cpp:.*atoi"
1415
"src/torcontrol.cpp:.*atoi"
1516
"src/torcontrol.cpp:.*strtol"
1617
"src/util/strencodings.cpp:.*atoi"

0 commit comments

Comments
 (0)