diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2019-10-12 07:50:22 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2019-10-15 22:47:08 +0000 |
commit | 58d67f1cc068c3779e309dc8a82ce33158c3e5b2 (patch) | |
tree | 68212fad8ce01013b923f13780e1a3e097c29c51 /src/test | |
parent | eb292af309aa57f3d7998b01307dd4cb91702908 (diff) | |
download | bitcoin-58d67f1cc068c3779e309dc8a82ce33158c3e5b2.tar.xz |
tests: Add fuzzing harness for descriptor Span-parsing helpers
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/spanparsing.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/fuzz/spanparsing.cpp b/src/test/fuzz/spanparsing.cpp new file mode 100644 index 0000000000..8e5e7dad11 --- /dev/null +++ b/src/test/fuzz/spanparsing.cpp @@ -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()); + } +} |