Bitcoin Core 32.99.0
P2P Digital Currency
parse_univalue.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-present 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 <chainparams.h>
6#include <rpc/util.h>
8#include <test/fuzz/fuzz.h>
9#include <univalue.h>
10#include <util/chaintype.h>
11
12#include <functional>
13#include <limits>
14#include <stdexcept>
15#include <string>
16
18{
20}
21
23{
24 const std::string random_string(buffer.begin(), buffer.end());
25 bool valid = true;
26 const UniValue univalue = [&] {
27 UniValue uv;
28 if (!uv.read(random_string)) valid = false;
29 return valid ? uv : UniValue{};
30 }();
31 if (!valid) {
32 return;
33 }
34 try {
35 (void)ParseHashO(univalue, "A");
36 } catch (const UniValue&) {
37 } catch (const std::runtime_error&) {
38 }
39 try {
40 (void)ParseHashO(univalue, random_string);
41 } catch (const UniValue&) {
42 } catch (const std::runtime_error&) {
43 }
44 try {
45 (void)ParseHashV(univalue, "A");
46 } catch (const UniValue&) {
47 } catch (const std::runtime_error&) {
48 }
49 try {
50 (void)ParseHashV(univalue, random_string);
51 } catch (const UniValue&) {
52 } catch (const std::runtime_error&) {
53 }
54 try {
55 (void)ParseHexO(univalue, "A");
56 } catch (const UniValue&) {
57 }
58 try {
59 (void)ParseHexO(univalue, random_string);
60 } catch (const UniValue&) {
61 }
62 try {
63 (void)ParseHexV(univalue, "A");
64 } catch (const UniValue&) {
65 } catch (const std::runtime_error&) {
66 }
67 try {
68 (void)ParseHexV(univalue, random_string);
69 } catch (const UniValue&) {
70 } catch (const std::runtime_error&) {
71 }
72 try {
73 if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue);
74 } catch (const UniValue&) {
75 }
76 try {
77 (void)AmountFromValue(univalue);
78 } catch (const UniValue&) {
79 } catch (const std::runtime_error&) {
80 }
81 try {
83 if (buffer.size() < 10'000) (void)EvalDescriptorStringOrObject(univalue, provider);
84 } catch (const UniValue&) {
85 } catch (const std::runtime_error&) {
86 }
87 try {
88 (void)ParseConfirmTarget(univalue, std::numeric_limits<unsigned int>::max());
89 } catch (const UniValue&) {
90 } catch (const std::runtime_error&) {
91 }
92 try {
93 (void)ParseDescriptorRange(univalue);
94 } catch (const UniValue&) {
95 } catch (const std::runtime_error&) {
96 }
97}
static CAmount AmountFromValue(const UniValue &value)
Definition: bitcoin-tx.cpp:556
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
bool isNull() const
Definition: univalue.h:81
bool isStr() const
Definition: univalue.h:85
bool read(std::string_view json)
Parse JSON; set value to null on failure.
Definition: basic.cpp:11
void initialize_parse_univalue()
FUZZ_TARGET(parse_univalue,.init=initialize_parse_univalue)
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider, const bool expand_priv)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
Definition: util.cpp:1338
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
Definition: util.cpp:1328
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
Definition: util.cpp:136
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
Definition: util.cpp:145
std::optional< int > ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
Definition: util.cpp:363
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
Definition: util.cpp:132
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
Definition: util.cpp:375
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: util.cpp:123
FuzzedDataProvider provider
Definition: dbwrapper.cpp:366
std::string random_string(uint32_t length)
Definition: test_kernel.cpp:36