torcontrol.cpp raw

   1  // Copyright (c) 2020-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 <test/fuzz/FuzzedDataProvider.h>
   6  #include <test/fuzz/fuzz.h>
   7  #include <test/fuzz/util.h>
   8  #include <test/util/setup_common.h>
   9  #include <torcontrol.h>
  10  
  11  #include <cstdint>
  12  #include <string>
  13  #include <vector>
  14  
  15  void initialize_torcontrol()
  16  {
  17      static const auto testing_setup = MakeNoLogFileContext<>();
  18  }
  19  
  20  FUZZ_TARGET(torcontrol, .init = initialize_torcontrol)
  21  {
  22      FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
  23  
  24      TorController tor_controller;
  25      CThreadInterrupt interrupt;
  26      TorControlConnection conn{interrupt};
  27  
  28      LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
  29          TorControlReply tor_control_reply;
  30          CallOneOf(
  31              fuzzed_data_provider,
  32              [&] {
  33                  tor_control_reply.code = TOR_REPLY_OK;
  34              },
  35              [&] {
  36                  tor_control_reply.code = TOR_REPLY_UNRECOGNIZED;
  37              },
  38              [&] {
  39                  tor_control_reply.code = TOR_REPLY_SYNTAX_ERROR;
  40              },
  41              [&] {
  42                  tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
  43              });
  44          tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider);
  45  
  46          CallOneOf(
  47              fuzzed_data_provider,
  48              [&] {
  49                  tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/true);
  50              },
  51              [&] {
  52                  tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/false);
  53              },
  54              [&] {
  55                  tor_controller.auth_cb(conn, tor_control_reply);
  56              },
  57              [&] {
  58                  tor_controller.authchallenge_cb(conn, tor_control_reply);
  59              },
  60              [&] {
  61                  tor_controller.protocolinfo_cb(conn, tor_control_reply);
  62              },
  63              [&] {
  64                  tor_controller.get_socks_cb(conn, tor_control_reply);
  65              });
  66      }
  67  }
  68