Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
torcontrol.cpp
Go to the documentation of this file.
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
{
17
static
const
auto
testing_setup =
MakeNoLogFileContext<>
();
18
}
19
20
FUZZ_TARGET
(torcontrol, .
init
=
initialize_torcontrol
)
21
{
22
FuzzedDataProvider
fuzzed_data_provider{buffer.data(), buffer.size()};
23
24
TorController
tor_controller;
25
CThreadInterrupt
interrupt;
26
TorControlConnection
conn{interrupt};
27
28
LIMITED_WHILE
(fuzzed_data_provider.
ConsumeBool
(), 10000) {
29
TorControlReply
tor_control_reply;
30
CallOneOf
(
31
fuzzed_data_provider,
32
[&] {
33
tor_control_reply.
code
=
TOR_REPLY_OK
;
34
},
35
[&] {
36
tor_control_reply.
code
=
TOR_REPLY_UNRECOGNIZED
;
37
},
38
[&] {
39
tor_control_reply.
code
=
TOR_REPLY_SYNTAX_ERROR
;
40
},
41
[&] {
42
tor_control_reply.
code
= fuzzed_data_provider.
ConsumeIntegral
<
int
>();
43
});
44
tor_control_reply.
lines
=
ConsumeRandomLengthStringVector
(fuzzed_data_provider);
45
46
CallOneOf
(
47
fuzzed_data_provider,
48
[&] {
49
tor_controller.
add_onion_cb
(conn, tor_control_reply,
/*pow_was_enabled=*/
true
);
50
},
51
[&] {
52
tor_controller.
add_onion_cb
(conn, tor_control_reply,
/*pow_was_enabled=*/
false
);
53
},
54
[&] {
55
tor_controller.
auth_cb
(conn, tor_control_reply);
56
},
57
[&] {
58
tor_controller.
authchallenge_cb
(conn, tor_control_reply);
59
},
60
[&] {
61
tor_controller.
protocolinfo_cb
(conn, tor_control_reply);
62
},
63
[&] {
64
tor_controller.
get_socks_cb
(conn, tor_control_reply);
65
});
66
}
67
}
FuzzedDataProvider.h
CThreadInterrupt
A helper class for interruptible sleeps.
Definition
threadinterrupt.h:26
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition
FuzzedDataProvider.h:195
TorControlConnection
Low-level handling for Tor control connection.
Definition
torcontrol.h:56
TorControlReply
Reply from Tor, can be single or multi-line.
Definition
torcontrol.h:38
TorControlReply::code
int code
Definition
torcontrol.h:42
TorControlReply::lines
std::vector< std::string > lines
Definition
torcontrol.h:43
TorController
Controller that connects to Tor control socket, authenticate, then create and maintain an ephemeral o...
Definition
torcontrol.h:123
TorController::get_socks_cb
void get_socks_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for GETINFO net/listeners/socks result.
Definition
torcontrol.cpp:413
TorController::add_onion_cb
void add_onion_cb(TorControlConnection &conn, const TorControlReply &reply, bool pow_was_enabled)
Callback for ADD_ONION result.
Definition
torcontrol.cpp:494
TorController::authchallenge_cb
void authchallenge_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for AUTHCHALLENGE result.
Definition
torcontrol.cpp:587
TorController::auth_cb
void auth_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for AUTHENTICATE result.
Definition
torcontrol.cpp:535
TorController::protocolinfo_cb
void protocolinfo_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for PROTOCOLINFO result.
Definition
torcontrol.cpp:626
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
LIMITED_WHILE
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition
fuzz.h:22
init
Definition
basic.cpp:11
setup_common.h
MakeNoLogFileContext
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Definition
setup_common.h:241
initialize_torcontrol
void initialize_torcontrol()
Definition
torcontrol.cpp:15
util.h
CallOneOf
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition
util.h:37
ConsumeRandomLengthStringVector
std::vector< std::string > ConsumeRandomLengthStringVector(FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16, const size_t max_string_length=16) noexcept
Definition
util.h:79
torcontrol.h
TOR_REPLY_SYNTAX_ERROR
constexpr int TOR_REPLY_SYNTAX_ERROR
Syntax error in command argument.
Definition
torcontrol.h:32
TOR_REPLY_OK
constexpr int TOR_REPLY_OK
Tor control reply code.
Definition
torcontrol.h:30
TOR_REPLY_UNRECOGNIZED
constexpr int TOR_REPLY_UNRECOGNIZED
Definition
torcontrol.h:31
Generated on
for Bitcoin Core by
1.18.0