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 [ + - ]: 1012 : FUZZ_TARGET(torcontrol, .init = initialize_torcontrol)
21 : : {
22 : 536 : FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
23 : :
24 : 536 : TorController tor_controller;
25 [ + - ]: 536 : CThreadInterrupt interrupt;
26 [ + - ]: 536 : TorControlConnection conn{interrupt};
27 : :
28 [ + + + + ]: 196840 : LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) {
29 : 196304 : TorControlReply tor_control_reply;
30 : 196304 : CallOneOf(
31 : : fuzzed_data_provider,
32 : 47858 : [&] {
33 : 47858 : tor_control_reply.code = TOR_REPLY_OK;
34 : 47858 : },
35 : 42979 : [&] {
36 : 42979 : tor_control_reply.code = TOR_REPLY_UNRECOGNIZED;
37 : 42979 : },
38 : 25210 : [&] {
39 : 25210 : tor_control_reply.code = TOR_REPLY_SYNTAX_ERROR;
40 : 25210 : },
41 : 80257 : [&] {
42 : 80257 : tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
43 : 80257 : });
44 : 196304 : tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider);
45 : :
46 [ + - ]: 196304 : CallOneOf(
47 : : fuzzed_data_provider,
48 : 34462 : [&] {
49 : 34462 : tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/true);
50 : 34462 : },
51 : 101068 : [&] {
52 : 101068 : tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/false);
53 : 101068 : },
54 : 12227 : [&] {
55 : 12227 : tor_controller.auth_cb(conn, tor_control_reply);
56 : 12227 : },
57 : 16421 : [&] {
58 : 16421 : tor_controller.authchallenge_cb(conn, tor_control_reply);
59 : 16421 : },
60 : 25691 : [&] {
61 : 25691 : tor_controller.protocolinfo_cb(conn, tor_control_reply);
62 : 25691 : },
63 : 6435 : [&] {
64 : 6435 : tor_controller.get_socks_cb(conn, tor_control_reply);
65 : 6435 : });
66 : 196304 : }
67 : 536 : }
|