Bitcoin Core  29.1.0
P2P Digital Currency
script_parsing.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 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 <script/parsing.h>
7 #include <test/fuzz/fuzz.h>
8 #include <util/string.h>
9 
10 using util::Split;
11 
12 FUZZ_TARGET(script_parsing)
13 {
14  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
15  const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
16  const std::string query = fuzzed_data_provider.ConsumeBytesAsString(std::min<size_t>(query_size, 1024 * 1024));
17  const std::string span_str = fuzzed_data_provider.ConsumeRemainingBytesAsString();
18  const Span<const char> const_span{span_str};
19 
20  Span<const char> mut_span = const_span;
21  (void)script::Const(query, mut_span);
22 
23  mut_span = const_span;
24  (void)script::Func(query, mut_span);
25 
26  mut_span = const_span;
27  (void)script::Expr(mut_span);
28 
29  if (!query.empty()) {
30  mut_span = const_span;
31  (void)Split(mut_span, query.front());
32  }
33 }
Span< const char > Expr(Span< const char > &sp)
Extract the expression that sp begins with.
Definition: parsing.cpp:33
bool Func(const std::string &str, Span< const char > &sp)
Parse a function call.
Definition: parsing.cpp:24
FUZZ_TARGET(script_parsing)
bool Const(const std::string &str, Span< const char > &sp)
Parse a constant.
Definition: parsing.cpp:15
CONSTEXPR_IF_NOT_DEBUG C & front() const noexcept
Definition: span.h:177
std::vector< T > Split(const Span< const char > &sp, std::string_view separators)
Split a string on any char found in separators, returning a vector.
Definition: string.h:107
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:97