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 #include <util/memory.h>
11 
12 #include <limits>
13 #include <string>
14 
initialize()15 void initialize()
16 {
17     static const ECCVerifyHandle verify_handle;
18     SelectParams(CBaseChainParams::REGTEST);
19 }
20 
test_one_input(const std::vector<uint8_t> & buffer)21 void test_one_input(const std::vector<uint8_t>& buffer)
22 {
23     const std::string random_string(buffer.begin(), buffer.end());
24     bool valid = true;
25     const UniValue univalue = [&] {
26         try {
27             return ParseNonRFCJSONValue(random_string);
28         } catch (const std::runtime_error&) {
29             valid = false;
30             return NullUniValue;
31         }
32     }();
33     if (!valid) {
34         return;
35     }
36     try {
37         (void)ParseHashO(univalue, "A");
38     } catch (const UniValue&) {
39     } catch (const std::runtime_error&) {
40     }
41     try {
42         (void)ParseHashO(univalue, random_string);
43     } catch (const UniValue&) {
44     } catch (const std::runtime_error&) {
45     }
46     try {
47         (void)ParseHashV(univalue, "A");
48     } catch (const UniValue&) {
49     } catch (const std::runtime_error&) {
50     }
51     try {
52         (void)ParseHashV(univalue, random_string);
53     } catch (const UniValue&) {
54     } catch (const std::runtime_error&) {
55     }
56     try {
57         (void)ParseHexO(univalue, "A");
58     } catch (const UniValue&) {
59     }
60     try {
61         (void)ParseHexO(univalue, random_string);
62     } catch (const UniValue&) {
63     }
64     try {
65         (void)ParseHexUV(univalue, "A");
66         (void)ParseHexUV(univalue, random_string);
67     } catch (const UniValue&) {
68     } catch (const std::runtime_error&) {
69     }
70     try {
71         (void)ParseHexV(univalue, "A");
72     } catch (const UniValue&) {
73     } catch (const std::runtime_error&) {
74     }
75     try {
76         (void)ParseHexV(univalue, random_string);
77     } catch (const UniValue&) {
78     } catch (const std::runtime_error&) {
79     }
80     try {
81         (void)ParseSighashString(univalue);
82     } catch (const std::runtime_error&) {
83     }
84     try {
85         (void)AmountFromValue(univalue);
86     } catch (const UniValue&) {
87     } catch (const std::runtime_error&) {
88     }
89     try {
90         FlatSigningProvider provider;
91         (void)EvalDescriptorStringOrObject(univalue, provider);
92     } catch (const UniValue&) {
93     } catch (const std::runtime_error&) {
94     }
95     try {
96         (void)ParseConfirmTarget(univalue, std::numeric_limits<unsigned int>::max());
97     } catch (const UniValue&) {
98     } catch (const std::runtime_error&) {
99     }
100     try {
101         (void)ParseDescriptorRange(univalue);
102     } catch (const UniValue&) {
103     } catch (const std::runtime_error&) {
104     }
105 }
106