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 : 1 : void initialize_torcontrol()
16 : : {
17 [ + - + - : 1 : static const auto testing_setup = MakeNoLogFileContext<>();
+ - ]
18 : 1 : }
19 : :
20 [ + - ]: 984 : FUZZ_TARGET(torcontrol, .init = initialize_torcontrol)
21 : : {
22 : 518 : FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
23 : :
24 : 518 : TorController tor_controller;
25 [ + - ]: 518 : CThreadInterrupt interrupt;
26 [ + - ]: 518 : TorControlConnection conn{interrupt};
27 : :
28 [ + + + + ]: 213390 : LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
29 : 212872 : TorControlReply tor_control_reply;
30 : 212872 : CallOneOf(
31 : : fuzzed_data_provider,
32 : 45972 : [&] {
33 : 45972 : tor_control_reply.code = TOR_REPLY_OK;
34 : 45972 : },
35 : 32135 : [&] {
36 : 32135 : tor_control_reply.code = TOR_REPLY_UNRECOGNIZED;
37 : 32135 : },
38 : 32388 : [&] {
39 : 32388 : tor_control_reply.code = TOR_REPLY_SYNTAX_ERROR;
40 : 32388 : },
41 : 102377 : [&] {
42 : 102377 : tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
43 : 102377 : });
44 : 212872 : tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider);
45 : :
46 [ + - ]: 212872 : CallOneOf(
47 : : fuzzed_data_provider,
48 : 41740 : [&] {
49 : 41740 : tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/true);
50 : 41740 : },
51 : 109952 : [&] {
52 : 109952 : tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/false);
53 : 109952 : },
54 : 14957 : [&] {
55 : 14957 : tor_controller.auth_cb(conn, tor_control_reply);
56 : 14957 : },
57 : 16129 : [&] {
58 : 16129 : tor_controller.authchallenge_cb(conn, tor_control_reply);
59 : 16129 : },
60 : 29101 : [&] {
61 : 29101 : tor_controller.protocolinfo_cb(conn, tor_control_reply);
62 : 29101 : },
63 : 993 : [&] {
64 : 993 : tor_controller.get_socks_cb(conn, tor_control_reply);
65 : 993 : });
66 : 212872 : }
67 : 518 : }
|