Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
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/client.h
>
7
#include <rpc/util.h>
8
#include <
test/fuzz/fuzz.h
>
9
#include <
util/chaintype.h
>
10
11
#include <limits>
12
#include <string>
13
14
void
initialize_parse_univalue
()
15
{
16
SelectParams
(
ChainType::REGTEST
);
17
}
18
19
FUZZ_TARGET
(parse_univalue, .
init
=
initialize_parse_univalue
)
20
{
21
const
std::string
random_string
(buffer.begin(), buffer.end());
22
bool
valid =
true
;
23
const
UniValue
univalue = [&] {
24
UniValue
uv;
25
if
(!uv.
read
(
random_string
)) valid =
false
;
26
return
valid ? uv :
UniValue
{};
27
}();
28
if
(!valid) {
29
return
;
30
}
31
try
{
32
(void)
ParseHashO
(univalue,
"A"
);
33
}
catch
(
const
UniValue
&) {
34
}
catch
(
const
std::runtime_error&) {
35
}
36
try
{
37
(void)
ParseHashO
(univalue,
random_string
);
38
}
catch
(
const
UniValue
&) {
39
}
catch
(
const
std::runtime_error&) {
40
}
41
try
{
42
(void)
ParseHashV
(univalue,
"A"
);
43
}
catch
(
const
UniValue
&) {
44
}
catch
(
const
std::runtime_error&) {
45
}
46
try
{
47
(void)
ParseHashV
(univalue,
random_string
);
48
}
catch
(
const
UniValue
&) {
49
}
catch
(
const
std::runtime_error&) {
50
}
51
try
{
52
(void)
ParseHexO
(univalue,
"A"
);
53
}
catch
(
const
UniValue
&) {
54
}
55
try
{
56
(void)
ParseHexO
(univalue,
random_string
);
57
}
catch
(
const
UniValue
&) {
58
}
59
try
{
60
(void)
ParseHexV
(univalue,
"A"
);
61
}
catch
(
const
UniValue
&) {
62
}
catch
(
const
std::runtime_error&) {
63
}
64
try
{
65
(void)
ParseHexV
(univalue,
random_string
);
66
}
catch
(
const
UniValue
&) {
67
}
catch
(
const
std::runtime_error&) {
68
}
69
try
{
70
if
(univalue.
isNull
() || univalue.
isStr
()) (void)
ParseSighashString
(univalue);
71
}
catch
(
const
UniValue
&) {
72
}
73
try
{
74
(void)
AmountFromValue
(univalue);
75
}
catch
(
const
UniValue
&) {
76
}
catch
(
const
std::runtime_error&) {
77
}
78
try
{
79
FlatSigningProvider
provider;
80
if
(buffer.size() < 10'000) (void)
EvalDescriptorStringOrObject
(univalue, provider);
81
}
catch
(
const
UniValue
&) {
82
}
catch
(
const
std::runtime_error&) {
83
}
84
try
{
85
(void)
ParseConfirmTarget
(univalue, std::numeric_limits<unsigned int>::max());
86
}
catch
(
const
UniValue
&) {
87
}
catch
(
const
std::runtime_error&) {
88
}
89
try
{
90
(void)
ParseDescriptorRange
(univalue);
91
}
catch
(
const
UniValue
&) {
92
}
catch
(
const
std::runtime_error&) {
93
}
94
}
AmountFromValue
static CAmount AmountFromValue(const UniValue &value)
Definition
bitcoin-tx.cpp:554
SelectParams
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
Definition
chainparams.cpp:140
chaintype.h
ChainType::REGTEST
@ REGTEST
Definition
chaintype.h:15
UniValue
Definition
univalue.h:22
UniValue::isNull
bool isNull() const
Definition
univalue.h:81
UniValue::read
bool read(std::string_view raw)
Definition
univalue_read.cpp:262
UniValue::isStr
bool isStr() const
Definition
univalue.h:85
client.h
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
init
Definition
bitcoin-gui.cpp:17
initialize_parse_univalue
void initialize_parse_univalue()
Definition
parse_univalue.cpp:14
EvalDescriptorStringOrObject
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:1324
ParseDescriptorRange
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
Definition
util.cpp:1308
ParseHexV
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
Definition
util.cpp:130
ParseHexO
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
Definition
util.cpp:139
ParseSighashString
std::optional< int > ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
Definition
util.cpp:357
ParseHashO
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
Definition
util.cpp:126
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:369
ParseHashV
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition
util.cpp:117
FlatSigningProvider
Definition
signingprovider.h:224
random_string
std::string random_string(uint32_t length)
Definition
test_kernel.cpp:29
Generated on
for Bitcoin Core by
1.17.0