LCOV - code coverage report
Current view: top level - src/test/fuzz - i2p.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 5 30 16.7 %
Date: 2023-09-26 12:08:55 Functions: 6 9 66.7 %

          Line data    Source code
       1             : // Copyright (c) 2020-2022 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/threadinterrupt.h>
      15             : 
      16           0 : void initialize_i2p()
      17           2 : {
      18           2 :     static const auto testing_setup = MakeNoLogFileContext<>();
      19           0 : }
      20             : 
      21           4 : FUZZ_TARGET(i2p, .init = initialize_i2p)
      22             : {
      23           0 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      24             : 
      25             :     // Mock CreateSock() to create FuzzedSock.
      26           0 :     auto CreateSockOrig = CreateSock;
      27           0 :     CreateSock = [&fuzzed_data_provider](const CService&) {
      28           0 :         return std::make_unique<FuzzedSock>(fuzzed_data_provider);
      29             :     };
      30             : 
      31           0 :     const CService sam_proxy;
      32           0 :     CThreadInterrupt interrupt;
      33             : 
      34           0 :     i2p::sam::Session sess{gArgs.GetDataDirNet() / "fuzzed_i2p_private_key", sam_proxy, &interrupt};
      35             : 
      36           0 :     i2p::Connection conn;
      37             : 
      38           0 :     if (sess.Listen(conn)) {
      39           0 :         if (sess.Accept(conn)) {
      40             :             try {
      41           0 :                 (void)conn.sock->RecvUntilTerminator('\n', 10ms, interrupt, i2p::sam::MAX_MSG_SIZE);
      42           0 :             } catch (const std::runtime_error&) {
      43           0 :             }
      44           0 :         }
      45           0 :     }
      46             : 
      47           0 :     const CService to;
      48             :     bool proxy_error;
      49             : 
      50           0 :     if (sess.Connect(to, conn, proxy_error)) {
      51             :         try {
      52           0 :             conn.sock->SendComplete("verack\n", 10ms, interrupt);
      53           0 :         } catch (const std::runtime_error&) {
      54           0 :         }
      55           0 :     }
      56             : 
      57           0 :     CreateSock = CreateSockOrig;
      58           0 : }

Generated by: LCOV version 1.14