/root/bitcoin/src/test/fuzz/parse_univalue.cpp
| Line | Count | Source | 
| 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 | 0 | { | 
| 16 | 0 |     SelectParams(ChainType::REGTEST); | 
| 17 | 0 | } | 
| 18 |  |  | 
| 19 |  | FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue) | 
| 20 | 0 | { | 
| 21 | 0 |     const std::string random_string(buffer.begin(), buffer.end()); | 
| 22 | 0 |     bool valid = true; | 
| 23 | 0 |     const UniValue univalue = [&] { | 
| 24 | 0 |         UniValue uv; | 
| 25 | 0 |         if (!uv.read(random_string)) valid = false; | 
| 26 | 0 |         return valid ? uv : UniValue{}; | 
| 27 | 0 |     }(); | 
| 28 | 0 |     if (!valid) { | 
| 29 | 0 |         return; | 
| 30 | 0 |     } | 
| 31 | 0 |     try { | 
| 32 | 0 |         (void)ParseHashO(univalue, "A"); | 
| 33 | 0 |     } catch (const UniValue&) { | 
| 34 | 0 |     } catch (const std::runtime_error&) { | 
| 35 | 0 |     } | 
| 36 | 0 |     try { | 
| 37 | 0 |         (void)ParseHashO(univalue, random_string); | 
| 38 | 0 |     } catch (const UniValue&) { | 
| 39 | 0 |     } catch (const std::runtime_error&) { | 
| 40 | 0 |     } | 
| 41 | 0 |     try { | 
| 42 | 0 |         (void)ParseHashV(univalue, "A"); | 
| 43 | 0 |     } catch (const UniValue&) { | 
| 44 | 0 |     } catch (const std::runtime_error&) { | 
| 45 | 0 |     } | 
| 46 | 0 |     try { | 
| 47 | 0 |         (void)ParseHashV(univalue, random_string); | 
| 48 | 0 |     } catch (const UniValue&) { | 
| 49 | 0 |     } catch (const std::runtime_error&) { | 
| 50 | 0 |     } | 
| 51 | 0 |     try { | 
| 52 | 0 |         (void)ParseHexO(univalue, "A"); | 
| 53 | 0 |     } catch (const UniValue&) { | 
| 54 | 0 |     } | 
| 55 | 0 |     try { | 
| 56 | 0 |         (void)ParseHexO(univalue, random_string); | 
| 57 | 0 |     } catch (const UniValue&) { | 
| 58 | 0 |     } | 
| 59 | 0 |     try { | 
| 60 | 0 |         (void)ParseHexV(univalue, "A"); | 
| 61 | 0 |     } catch (const UniValue&) { | 
| 62 | 0 |     } catch (const std::runtime_error&) { | 
| 63 | 0 |     } | 
| 64 | 0 |     try { | 
| 65 | 0 |         (void)ParseHexV(univalue, random_string); | 
| 66 | 0 |     } catch (const UniValue&) { | 
| 67 | 0 |     } catch (const std::runtime_error&) { | 
| 68 | 0 |     } | 
| 69 | 0 |     try { | 
| 70 | 0 |         if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue); | 
| 71 | 0 |     } catch (const UniValue&) { | 
| 72 | 0 |     } | 
| 73 | 0 |     try { | 
| 74 | 0 |         (void)AmountFromValue(univalue); | 
| 75 | 0 |     } catch (const UniValue&) { | 
| 76 | 0 |     } catch (const std::runtime_error&) { | 
| 77 | 0 |     } | 
| 78 | 0 |     try { | 
| 79 | 0 |         FlatSigningProvider provider; | 
| 80 | 0 |         if (buffer.size() < 10'000) (void)EvalDescriptorStringOrObject(univalue, provider); | 
| 81 | 0 |     } catch (const UniValue&) { | 
| 82 | 0 |     } catch (const std::runtime_error&) { | 
| 83 | 0 |     } | 
| 84 | 0 |     try { | 
| 85 | 0 |         (void)ParseConfirmTarget(univalue, std::numeric_limits<unsigned int>::max()); | 
| 86 | 0 |     } catch (const UniValue&) { | 
| 87 | 0 |     } catch (const std::runtime_error&) { | 
| 88 | 0 |     } | 
| 89 | 0 |     try { | 
| 90 | 0 |         (void)ParseDescriptorRange(univalue); | 
| 91 | 0 |     } catch (const UniValue&) { | 
| 92 | 0 |     } catch (const std::runtime_error&) { | 
| 93 | 0 |     } | 
| 94 | 0 | } |