Branch data Line data Source code
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 : 50726 : class DummyTorControlConnection : public TorControlConnection
16 : : {
17 : : public:
18 : 50726 : DummyTorControlConnection() : TorControlConnection{nullptr}
19 : : {
20 : 50726 : }
21 : :
22 : : bool Connect(const std::string&, const ConnectionCB&, const ConnectionCB&)
23 : : {
24 : : return true;
25 : : }
26 : :
27 : : void Disconnect()
28 : : {
29 : : }
30 : :
31 : : bool Command(const std::string&, const ReplyHandlerCB&)
32 : : {
33 : : return true;
34 : : }
35 : : };
36 : :
37 : 1 : void initialize_torcontrol()
38 : : {
39 [ + - + - : 1 : static const auto testing_setup = MakeNoLogFileContext<>();
+ - ]
40 : 1 : }
41 : :
42 [ + - ]: 701 : FUZZ_TARGET(torcontrol, .init = initialize_torcontrol)
43 : : {
44 : 243 : FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
45 : :
46 : 243 : TorController tor_controller;
47 [ + + + + ]: 50969 : LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
48 : 50760 : TorControlReply tor_control_reply;
49 : 50760 : CallOneOf(
50 : : fuzzed_data_provider,
51 : 6488 : [&] {
52 : 6488 : tor_control_reply.code = TOR_REPLY_OK;
53 : 6488 : },
54 : 19285 : [&] {
55 : 19285 : tor_control_reply.code = TOR_REPLY_UNRECOGNIZED;
56 : 19285 : },
57 : 4711 : [&] {
58 : 4711 : tor_control_reply.code = TOR_REPLY_SYNTAX_ERROR;
59 : 4711 : },
60 : 20276 : [&] {
61 : 20276 : tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
62 : 20276 : });
63 : 50760 : tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider);
64 [ + + ]: 50760 : if (tor_control_reply.lines.empty()) {
65 : : break;
66 : : }
67 [ + - ]: 50726 : DummyTorControlConnection dummy_tor_control_connection;
68 [ + - ]: 50726 : CallOneOf(
69 : : fuzzed_data_provider,
70 : 5165 : [&] {
71 : 5165 : tor_controller.add_onion_cb(dummy_tor_control_connection, tor_control_reply, /*pow_was_enabled=*/true);
72 : 5165 : },
73 : 13795 : [&] {
74 : 13795 : tor_controller.add_onion_cb(dummy_tor_control_connection, tor_control_reply, /*pow_was_enabled=*/false);
75 : 13795 : },
76 : 5162 : [&] {
77 : 5162 : tor_controller.auth_cb(dummy_tor_control_connection, tor_control_reply);
78 : 5162 : },
79 : 22088 : [&] {
80 : 22088 : tor_controller.authchallenge_cb(dummy_tor_control_connection, tor_control_reply);
81 : 22088 : },
82 : 4516 : [&] {
83 : 4516 : tor_controller.protocolinfo_cb(dummy_tor_control_connection, tor_control_reply);
84 : 4516 : });
85 : 50760 : }
86 : 243 : }
|