/root/bitcoin/src/test/fuzz/torcontrol.cpp
| Line | Count | Source | 
| 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 <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 |  | class DummyTorControlConnection : public TorControlConnection | 
| 16 |  | { | 
| 17 |  | public: | 
| 18 | 0 |     DummyTorControlConnection() : TorControlConnection{nullptr} | 
| 19 | 0 |     { | 
| 20 | 0 |     } | 
| 21 |  |  | 
| 22 |  |     bool Connect(const std::string&, const ConnectionCB&, const ConnectionCB&) | 
| 23 | 0 |     { | 
| 24 | 0 |         return true; | 
| 25 | 0 |     } | 
| 26 |  |  | 
| 27 |  |     void Disconnect() | 
| 28 | 0 |     { | 
| 29 | 0 |     } | 
| 30 |  |  | 
| 31 |  |     bool Command(const std::string&, const ReplyHandlerCB&) | 
| 32 | 0 |     { | 
| 33 | 0 |         return true; | 
| 34 | 0 |     } | 
| 35 |  | }; | 
| 36 |  |  | 
| 37 |  | void initialize_torcontrol() | 
| 38 | 0 | { | 
| 39 | 0 |     static const auto testing_setup = MakeNoLogFileContext<>(); | 
| 40 | 0 | } | 
| 41 |  |  | 
| 42 |  | FUZZ_TARGET(torcontrol, .init = initialize_torcontrol) | 
| 43 | 0 | { | 
| 44 | 0 |     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; | 
| 45 |  | 
 | 
| 46 | 0 |     TorController tor_controller; | 
| 47 | 0 |     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) { | 
| 48 | 0 |         TorControlReply tor_control_reply; | 
| 49 | 0 |         CallOneOf( | 
| 50 | 0 |             fuzzed_data_provider, | 
| 51 | 0 |             [&] { | 
| 52 | 0 |                 tor_control_reply.code = 250; | 
| 53 | 0 |             }, | 
| 54 | 0 |             [&] { | 
| 55 | 0 |                 tor_control_reply.code = 510; | 
| 56 | 0 |             }, | 
| 57 | 0 |             [&] { | 
| 58 | 0 |                 tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>(); | 
| 59 | 0 |             }); | 
| 60 | 0 |         tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider); | 
| 61 | 0 |         if (tor_control_reply.lines.empty()) { | 
| 62 | 0 |             break; | 
| 63 | 0 |         } | 
| 64 | 0 |         DummyTorControlConnection dummy_tor_control_connection; | 
| 65 | 0 |         CallOneOf( | 
| 66 | 0 |             fuzzed_data_provider, | 
| 67 | 0 |             [&] { | 
| 68 | 0 |                 tor_controller.add_onion_cb(dummy_tor_control_connection, tor_control_reply); | 
| 69 | 0 |             }, | 
| 70 | 0 |             [&] { | 
| 71 | 0 |                 tor_controller.auth_cb(dummy_tor_control_connection, tor_control_reply); | 
| 72 | 0 |             }, | 
| 73 | 0 |             [&] { | 
| 74 | 0 |                 tor_controller.authchallenge_cb(dummy_tor_control_connection, tor_control_reply); | 
| 75 | 0 |             }, | 
| 76 | 0 |             [&] { | 
| 77 | 0 |                 tor_controller.protocolinfo_cb(dummy_tor_control_connection, tor_control_reply); | 
| 78 | 0 |             }); | 
| 79 | 0 |     } | 
| 80 | 0 | } |