LCOV - code coverage report
Current view: top level - src/test/fuzz - asmap_direct.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 23 23
Test Date: 2024-12-04 04:00:22 Functions: 100.0 % 2 2
Branches: 80.0 % 40 32

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-2021 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 <netaddress.h>
       6                 :             : #include <util/asmap.h>
       7                 :             : #include <test/fuzz/fuzz.h>
       8                 :             : 
       9                 :             : #include <cstdint>
      10                 :             : #include <optional>
      11                 :             : #include <vector>
      12                 :             : 
      13                 :             : #include <assert.h>
      14                 :             : 
      15         [ +  - ]:         632 : FUZZ_TARGET(asmap_direct)
      16                 :             : {
      17                 :             :     // Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte]
      18                 :         220 :     std::optional<size_t> sep_pos_opt;
      19         [ +  + ]:      100402 :     for (size_t pos = 0; pos < buffer.size(); ++pos) {
      20         [ +  + ]:      100186 :         uint8_t x = buffer[pos];
      21         [ +  + ]:      100186 :         if ((x & 0xFE) == 0) continue;
      22         [ +  + ]:         220 :         if (x == 0xFF) {
      23         [ +  + ]:         218 :             if (sep_pos_opt) return;
      24                 :         216 :             sep_pos_opt = pos;
      25                 :             :         } else {
      26                 :             :             return;
      27                 :             :         }
      28                 :             :     }
      29         [ +  + ]:         216 :     if (!sep_pos_opt) return; // Needs exactly 1 separator
      30         [ +  + ]:         214 :     const size_t sep_pos{sep_pos_opt.value()};
      31         [ +  + ]:         214 :     if (buffer.size() - sep_pos - 1 > 128) return; // At most 128 bits in IP address
      32                 :             : 
      33                 :             :     // Checks on asmap
      34                 :         212 :     std::vector<bool> asmap(buffer.begin(), buffer.begin() + sep_pos);
      35   [ +  -  +  + ]:         212 :     if (SanityCheckASMap(asmap, buffer.size() - 1 - sep_pos)) {
      36                 :             :         // Verify that for valid asmaps, no prefix (except up to 7 zero padding bits) is valid.
      37         [ +  - ]:         140 :         std::vector<bool> asmap_prefix = asmap;
      38   [ +  -  +  +  :         634 :         while (!asmap_prefix.empty() && asmap_prefix.size() + 7 > asmap.size() && asmap_prefix.back() == false) {
                   +  + ]
      39                 :         494 :             asmap_prefix.pop_back();
      40                 :             :         }
      41         [ +  + ]:       67967 :         while (!asmap_prefix.empty()) {
      42                 :       67827 :             asmap_prefix.pop_back();
      43   [ +  -  -  + ]:       67827 :             assert(!SanityCheckASMap(asmap_prefix, buffer.size() - 1 - sep_pos));
      44                 :             :         }
      45                 :             :         // No address input should trigger assertions in interpreter
      46         [ +  - ]:         140 :         std::vector<bool> addr(buffer.begin() + sep_pos + 1, buffer.end());
      47         [ +  - ]:         140 :         (void)Interpret(asmap, addr);
      48                 :         140 :     }
      49                 :         212 : }
        

Generated by: LCOV version 2.0-1