LCOV - code coverage report
Current view: top level - src/test/fuzz - i2p.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 64.5 % 31 20
Test Date: 2024-07-07 04:03:53 Functions: 75.0 % 4 3
Branches: 32.1 % 56 18

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 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 <common/args.h>
       6                 :             : #include <i2p.h>
       7                 :             : #include <netaddress.h>
       8                 :             : #include <netbase.h>
       9                 :             : #include <test/fuzz/FuzzedDataProvider.h>
      10                 :             : #include <test/fuzz/fuzz.h>
      11                 :             : #include <test/fuzz/util.h>
      12                 :             : #include <test/fuzz/util/net.h>
      13                 :             : #include <test/util/setup_common.h>
      14                 :             : #include <util/fs_helpers.h>
      15                 :             : #include <util/threadinterrupt.h>
      16                 :             : 
      17                 :           0 : void initialize_i2p()
      18                 :             : {
      19   [ #  #  #  #  :           0 :     static const auto testing_setup = MakeNoLogFileContext<>();
                   #  # ]
      20                 :           0 : }
      21                 :             : 
      22         [ +  - ]:         235 : FUZZ_TARGET(i2p, .init = initialize_i2p)
      23                 :             : {
      24                 :         233 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      25                 :             : 
      26                 :         233 :     SetMockTime(ConsumeTime(fuzzed_data_provider));
      27                 :             : 
      28                 :             :     // Mock CreateSock() to create FuzzedSock.
      29                 :         233 :     auto CreateSockOrig = CreateSock;
      30                 :         722 :     CreateSock = [&fuzzed_data_provider](int, int, int) {
      31                 :         489 :         return std::make_unique<FuzzedSock>(fuzzed_data_provider);
      32                 :             :     };
      33                 :             : 
      34   [ +  -  +  - ]:         233 :     const fs::path private_key_path = gArgs.GetDataDirNet() / "fuzzed_i2p_private_key";
      35         [ +  - ]:         233 :     const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), 7656};
      36         [ +  - ]:         233 :     const Proxy sam_proxy{addr, false};
      37         [ +  - ]:         233 :     CThreadInterrupt interrupt;
      38                 :             : 
      39         [ +  - ]:         233 :     i2p::sam::Session session{private_key_path, sam_proxy, &interrupt};
      40         [ +  - ]:         233 :     i2p::Connection conn;
      41                 :             : 
      42   [ +  -  +  + ]:         233 :     if (session.Listen(conn)) {
      43   [ +  -  +  - ]:           1 :         if (session.Accept(conn)) {
      44                 :             :             try {
      45   [ #  #  #  # ]:           0 :                 (void)conn.sock->RecvUntilTerminator('\n', 10ms, interrupt, i2p::sam::MAX_MSG_SIZE);
      46         [ #  # ]:           0 :             } catch (const std::runtime_error&) {
      47         [ #  # ]:           0 :             }
      48                 :           0 :         }
      49                 :           1 :     }
      50                 :             : 
      51                 :         233 :     bool proxy_error;
      52                 :             : 
      53   [ +  -  +  -  :         233 :     if (session.Connect(CService{}, conn, proxy_error)) {
                   +  - ]
      54                 :             :         try {
      55   [ #  #  #  # ]:           0 :             conn.sock->SendComplete("verack\n", 10ms, interrupt);
      56         [ #  # ]:           0 :         } catch (const std::runtime_error&) {
      57         [ #  # ]:           0 :         }
      58                 :           0 :     }
      59                 :             : 
      60         [ +  - ]:         233 :     fs::remove_all(private_key_path);
      61                 :             : 
      62         [ +  - ]:         233 :     CreateSock = CreateSockOrig;
      63                 :         233 : }
        

Generated by: LCOV version 2.0-1