LCOV - code coverage report
Current view: top level - src/test/fuzz - i2p.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 33 33
Test Date: 2026-07-11 06:27:17 Functions: 100.0 % 3 3
Branches: 59.6 % 52 31

             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 <compat/compat.h>
       7                 :             : #include <i2p.h>
       8                 :             : #include <netaddress.h>
       9                 :             : #include <netbase.h>
      10                 :             : #include <test/fuzz/FuzzedDataProvider.h>
      11                 :             : #include <test/fuzz/fuzz.h>
      12                 :             : #include <test/fuzz/util.h>
      13                 :             : #include <test/fuzz/util/net.h>
      14                 :             : #include <test/fuzz/util/threadinterrupt.h>
      15                 :             : #include <test/util/setup_common.h>
      16                 :             : #include <test/util/time.h>
      17                 :             : #include <util/fs_helpers.h>
      18                 :             : #include <util/threadinterrupt.h>
      19                 :             : 
      20                 :           1 : void initialize_i2p()
      21                 :             : {
      22   [ +  -  +  -  :           1 :     static const auto testing_setup = MakeNoLogFileContext<>();
                   +  - ]
      23                 :           1 : }
      24                 :             : 
      25         [ +  - ]:         973 : FUZZ_TARGET(i2p, .init = initialize_i2p)
      26                 :             : {
      27                 :         501 :     SeedRandomStateForTest(SeedRand::ZEROS);
      28                 :         501 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      29                 :             : 
      30                 :         501 :     FakeNodeClock clock{ConsumeTime(fuzzed_data_provider)};
      31         [ +  - ]:         501 :     FakeSteadyClock steady_clock;
      32                 :             : 
      33                 :             :     // Mock CreateSock() to create FuzzedSock.
      34         [ +  - ]:         501 :     auto CreateSockOrig = CreateSock;
      35                 :        1748 :     CreateSock = [&fuzzed_data_provider, &steady_clock](int, int, int) {
      36                 :        1247 :         return std::make_unique<FuzzedSock>(fuzzed_data_provider, steady_clock);
      37                 :         501 :     };
      38                 :             : 
      39         [ +  - ]:        1002 :     const fs::path private_key_path = gArgs.GetDataDirNet() / "fuzzed_i2p_private_key";
      40         [ +  - ]:         501 :     const CService addr{in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT), 7656};
      41                 :         501 :     const Proxy sam_proxy{addr, /*tor_stream_isolation=*/false};
      42         [ +  - ]:         501 :     auto interrupt{ConsumeThreadInterrupt(fuzzed_data_provider)};
      43                 :             : 
      44   [ +  -  +  - ]:        1002 :     i2p::sam::Session session{private_key_path, sam_proxy, interrupt};
      45         [ +  - ]:         501 :     i2p::Connection conn;
      46                 :             : 
      47   [ +  -  +  + ]:         501 :     if (session.Listen(conn)) {
      48   [ +  -  +  + ]:         104 :         if (session.Accept(conn)) {
      49                 :          28 :             try {
      50         [ +  + ]:          47 :                 (void)conn.sock->RecvUntilTerminator('\n', 10ms, *interrupt, i2p::sam::MAX_MSG_SIZE);
      51         [ -  + ]:           9 :             } catch (const std::runtime_error&) {
      52                 :           9 :             }
      53                 :             :         }
      54                 :             :     }
      55                 :             : 
      56                 :         501 :     bool proxy_error;
      57                 :             : 
      58   [ +  -  +  -  :         501 :     if (session.Connect(CService{}, conn, proxy_error)) {
                   +  + ]
      59                 :          16 :         try {
      60         [ +  + ]:          16 :             conn.sock->SendComplete("verack\n", 10ms, *interrupt);
      61         [ -  + ]:           9 :         } catch (const std::runtime_error&) {
      62                 :           9 :         }
      63                 :             :     }
      64                 :             : 
      65         [ +  - ]:         501 :     fs::remove(private_key_path);
      66                 :             : 
      67         [ +  - ]:         501 :     CreateSock = CreateSockOrig;
      68         [ +  - ]:        2004 : }
        

Generated by: LCOV version 2.0-1