Bitcoin Core  22.99.0
P2P Digital Currency
parse_univalue.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-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 <chainparams.h>
6 #include <core_io.h>
7 #include <rpc/client.h>
8 #include <rpc/util.h>
9 #include <test/fuzz/fuzz.h>
10 
11 #include <limits>
12 #include <string>
13 
15 {
16  static const ECCVerifyHandle verify_handle;
18 }
19 
21 {
22  const std::string random_string(buffer.begin(), buffer.end());
23  bool valid = true;
24  const UniValue univalue = [&] {
25  try {
26  return ParseNonRFCJSONValue(random_string);
27  } catch (const std::runtime_error&) {
28  valid = false;
29  return NullUniValue;
30  }
31  }();
32  if (!valid) {
33  return;
34  }
35  try {
36  (void)ParseHashO(univalue, "A");
37  } catch (const UniValue&) {
38  } catch (const std::runtime_error&) {
39  }
40  try {
41  (void)ParseHashO(univalue, random_string);
42  } catch (const UniValue&) {
43  } catch (const std::runtime_error&) {
44  }
45  try {
46  (void)ParseHashV(univalue, "A");
47  } catch (const UniValue&) {
48  } catch (const std::runtime_error&) {
49  }
50  try {
51  (void)ParseHashV(univalue, random_string);
52  } catch (const UniValue&) {
53  } catch (const std::runtime_error&) {
54  }
55  try {
56  (void)ParseHexO(univalue, "A");
57  } catch (const UniValue&) {
58  }
59  try {
60  (void)ParseHexO(univalue, random_string);
61  } catch (const UniValue&) {
62  }
63  try {
64  (void)ParseHexUV(univalue, "A");
65  (void)ParseHexUV(univalue, random_string);
66  } catch (const UniValue&) {
67  } catch (const std::runtime_error&) {
68  }
69  try {
70  (void)ParseHexV(univalue, "A");
71  } catch (const UniValue&) {
72  } catch (const std::runtime_error&) {
73  }
74  try {
75  (void)ParseHexV(univalue, random_string);
76  } catch (const UniValue&) {
77  } catch (const std::runtime_error&) {
78  }
79  try {
80  (void)ParseSighashString(univalue);
81  } catch (const std::runtime_error&) {
82  }
83  try {
84  (void)AmountFromValue(univalue);
85  } catch (const UniValue&) {
86  } catch (const std::runtime_error&) {
87  }
88  try {
89  FlatSigningProvider provider;
90  (void)EvalDescriptorStringOrObject(univalue, provider);
91  } catch (const UniValue&) {
92  } catch (const std::runtime_error&) {
93  }
94  try {
95  (void)ParseConfirmTarget(univalue, std::numeric_limits<unsigned int>::max());
96  } catch (const UniValue&) {
97  } catch (const std::runtime_error&) {
98  }
99  try {
100  (void)ParseDescriptorRange(univalue);
101  } catch (const UniValue&) {
102  } catch (const std::runtime_error&) {
103  }
104 }
ParseHexO
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
Definition: util.cpp:111
ParseConfirmTarget
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:329
initialize_parse_univalue
void initialize_parse_univalue()
Definition: parse_univalue.cpp:14
NullUniValue
const UniValue NullUniValue
Definition: univalue.cpp:13
ParseHashV
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: util.cpp:89
FUZZ_TARGET_INIT
FUZZ_TARGET_INIT(parse_univalue, initialize_parse_univalue)
Definition: parse_univalue.cpp:20
chainparams.h
core_io.h
UniValue
Definition: univalue.h:19
ParseHexV
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
Definition: util.cpp:102
CBaseChainParams::REGTEST
static const std::string REGTEST
Definition: chainparamsbase.h:25
SelectParams
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
Definition: chainparams.cpp:555
EvalDescriptorStringOrObject
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
Definition: util.cpp:991
ParseDescriptorRange
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
Definition: util.cpp:975
ParseHashO
uint256 ParseHashO(const UniValue &o, std::string strKey)
Definition: util.cpp:98
ECCVerifyHandle
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:315
fuzz.h
util.h
ParseHexUV
std::vector< unsigned char > ParseHexUV(const UniValue &v, const std::string &strName)
Definition: core_read.cpp:248
AmountFromValue
static CAmount AmountFromValue(const UniValue &value)
Definition: bitcoin-tx.cpp:538
ParseNonRFCJSONValue
UniValue ParseNonRFCJSONValue(const std::string &strVal)
Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) as well as obje...
Definition: client.cpp:229
client.h
FlatSigningProvider
Definition: signingprovider.h:73
ParseSighashString
int ParseSighashString(const UniValue &sighash)
Definition: core_read.cpp:258