Bitcoin Core
32.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/util.h>
7
#include <
script/signingprovider.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
17
void
initialize_parse_univalue
()
18
{
19
SelectParams
(
ChainType::REGTEST
);
20
}
21
22
FUZZ_TARGET
(parse_univalue, .
init
=
initialize_parse_univalue
)
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
{
82
FlatSigningProvider
provider
;
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
}
SelectParams
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
Definition
chainparams.cpp:165
chaintype.h
ChainType::REGTEST
@ REGTEST
Definition
chaintype.h:16
UniValue
Definition
univalue.h:22
UniValue::isNull
bool isNull() const
Definition
univalue.h:81
UniValue::isStr
bool isStr() const
Definition
univalue.h:85
UniValue::read
bool read(std::string_view json)
Parse JSON; set value to null on failure.
Definition
univalue_read.cpp:264
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
init
Definition
basic.cpp:11
initialize_parse_univalue
void initialize_parse_univalue()
Definition
parse_univalue.cpp:17
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:1344
ParseDescriptorRange
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
Definition
util.cpp:1328
AmountFromValue
CAmount AmountFromValue(const UniValue &value, int decimals)
Validate and return a CAmount from a UniValue number or string.
Definition
util.cpp:103
ParseHexV
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
Definition
util.cpp:135
ParseHexO
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
Definition
util.cpp:144
ParseSighashString
std::optional< int > ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
Definition
util.cpp:362
ParseHashO
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
Definition
util.cpp:131
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:374
ParseHashV
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition
util.cpp:122
signingprovider.h
FlatSigningProvider
Definition
signingprovider.h:235
provider
FuzzedDataProvider provider
Definition
dbwrapper.cpp:366
random_string
std::string random_string(uint32_t length)
Definition
test_kernel.cpp:33
univalue.h
Generated on
for Bitcoin Core by
1.18.0