mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#17113: Add fuzzing harness for descriptor Span-parsing helpers
This commit is contained in:
parent
d3c28bf50b
commit
a9d0cbb8f7
@ -54,6 +54,7 @@ FUZZ_TARGETS = \
|
|||||||
test/fuzz/script_deserialize \
|
test/fuzz/script_deserialize \
|
||||||
test/fuzz/script_flags \
|
test/fuzz/script_flags \
|
||||||
test/fuzz/service_deserialize \
|
test/fuzz/service_deserialize \
|
||||||
|
test/fuzz/spanparsing \
|
||||||
test/fuzz/sub_net_deserialize \
|
test/fuzz/sub_net_deserialize \
|
||||||
test/fuzz/transaction \
|
test/fuzz/transaction \
|
||||||
test/fuzz/tx_in \
|
test/fuzz/tx_in \
|
||||||
@ -367,6 +368,12 @@ test_fuzz_service_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
|||||||
test_fuzz_service_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
test_fuzz_service_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||||
test_fuzz_service_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
test_fuzz_service_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||||
|
|
||||||
|
test_fuzz_spanparsing_SOURCES = $(FUZZ_SUITE) test/fuzz/spanparsing.cpp
|
||||||
|
test_fuzz_spanparsing_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||||
|
test_fuzz_spanparsing_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
|
test_fuzz_spanparsing_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||||
|
test_fuzz_spanparsing_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||||
|
|
||||||
test_fuzz_messageheader_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
|
test_fuzz_messageheader_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
|
||||||
test_fuzz_messageheader_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DMESSAGEHEADER_DESERIALIZE=1
|
test_fuzz_messageheader_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DMESSAGEHEADER_DESERIALIZE=1
|
||||||
test_fuzz_messageheader_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
test_fuzz_messageheader_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
|
30
src/test/fuzz/spanparsing.cpp
Normal file
30
src/test/fuzz/spanparsing.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (c) 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/FuzzedDataProvider.h>
|
||||||
|
#include <test/fuzz/fuzz.h>
|
||||||
|
#include <util/spanparsing.h>
|
||||||
|
|
||||||
|
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
|
{
|
||||||
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
|
const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||||
|
const std::string query = fuzzed_data_provider.ConsumeBytesAsString(std::min<size_t>(query_size, 1024 * 1024));
|
||||||
|
const std::string span_str = fuzzed_data_provider.ConsumeRemainingBytesAsString();
|
||||||
|
const Span<const char> const_span = MakeSpan(span_str);
|
||||||
|
|
||||||
|
Span<const char> mut_span = const_span;
|
||||||
|
(void)spanparsing::Const(query, mut_span);
|
||||||
|
|
||||||
|
mut_span = const_span;
|
||||||
|
(void)spanparsing::Func(query, mut_span);
|
||||||
|
|
||||||
|
mut_span = const_span;
|
||||||
|
(void)spanparsing::Expr(mut_span);
|
||||||
|
|
||||||
|
if (!query.empty()) {
|
||||||
|
mut_span = const_span;
|
||||||
|
(void)spanparsing::Split(mut_span, query.front());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user