LCOV - code coverage report
Current view: top level - src/test/fuzz - parse_univalue.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 96.1 % 77 74
Test Date: 2026-10-13 06:24:39 Functions: 100.0 % 4 4
Branches: 68.8 % 96 66

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

Generated by: LCOV version 2.5.0-full