/root/bitcoin/src/test/fuzz/torcontrol.cpp
Line | Count | Source |
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 | 0 | { |
17 | 0 | static const auto testing_setup = MakeNoLogFileContext<>(); |
18 | 0 | } |
19 | | |
20 | | FUZZ_TARGET(torcontrol, .init = initialize_torcontrol) |
21 | 0 | { |
22 | 0 | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; |
23 | |
|
24 | 0 | TorController tor_controller; |
25 | 0 | CThreadInterrupt interrupt; |
26 | 0 | TorControlConnection conn{interrupt}; |
27 | |
|
28 | 0 | LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) { |
29 | 0 | TorControlReply tor_control_reply; |
30 | 0 | CallOneOf( |
31 | 0 | fuzzed_data_provider, |
32 | 0 | [&] { |
33 | 0 | tor_control_reply.code = TOR_REPLY_OK; |
34 | 0 | }, |
35 | 0 | [&] { |
36 | 0 | tor_control_reply.code = TOR_REPLY_UNRECOGNIZED; |
37 | 0 | }, |
38 | 0 | [&] { |
39 | 0 | tor_control_reply.code = TOR_REPLY_SYNTAX_ERROR; |
40 | 0 | }, |
41 | 0 | [&] { |
42 | 0 | tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>(); |
43 | 0 | }); |
44 | 0 | tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider); |
45 | |
|
46 | 0 | CallOneOf( |
47 | 0 | fuzzed_data_provider, |
48 | 0 | [&] { |
49 | 0 | tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/true); |
50 | 0 | }, |
51 | 0 | [&] { |
52 | 0 | tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/false); |
53 | 0 | }, |
54 | 0 | [&] { |
55 | 0 | tor_controller.auth_cb(conn, tor_control_reply); |
56 | 0 | }, |
57 | 0 | [&] { |
58 | 0 | tor_controller.authchallenge_cb(conn, tor_control_reply); |
59 | 0 | }, |
60 | 0 | [&] { |
61 | 0 | tor_controller.protocolinfo_cb(conn, tor_control_reply); |
62 | 0 | }, |
63 | 0 | [&] { |
64 | 0 | tor_controller.get_socks_cb(conn, tor_control_reply); |
65 | 0 | }); |
66 | 0 | } |
67 | 0 | } |