Bitcoin Core
31.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
class
DummyTorControlConnection
:
public
TorControlConnection
16
{
17
public
:
18
DummyTorControlConnection
() :
TorControlConnection
{nullptr}
19
{
20
}
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
void
initialize_torcontrol
()
38
{
39
static
const
auto
testing_setup =
MakeNoLogFileContext<>
();
40
}
41
42
FUZZ_TARGET
(torcontrol, .
init
=
initialize_torcontrol
)
43
{
44
FuzzedDataProvider
fuzzed_data_provider{buffer.data(), buffer.size()};
45
46
TorController
tor_controller;
47
LIMITED_WHILE
(fuzzed_data_provider.
ConsumeBool
(), 10000) {
48
TorControlReply
tor_control_reply;
49
CallOneOf
(
50
fuzzed_data_provider,
51
[&] {
52
tor_control_reply.
code
= 250;
53
},
54
[&] {
55
tor_control_reply.
code
= 510;
56
},
57
[&] {
58
tor_control_reply.
code
= fuzzed_data_provider.
ConsumeIntegral
<
int
>();
59
});
60
tor_control_reply.
lines
=
ConsumeRandomLengthStringVector
(fuzzed_data_provider);
61
if
(tor_control_reply.
lines
.empty()) {
62
break
;
63
}
64
DummyTorControlConnection
dummy_tor_control_connection;
65
CallOneOf
(
66
fuzzed_data_provider,
67
[&] {
68
tor_controller.
add_onion_cb
(dummy_tor_control_connection, tor_control_reply);
69
},
70
[&] {
71
tor_controller.
auth_cb
(dummy_tor_control_connection, tor_control_reply);
72
},
73
[&] {
74
tor_controller.
authchallenge_cb
(dummy_tor_control_connection, tor_control_reply);
75
},
76
[&] {
77
tor_controller.
protocolinfo_cb
(dummy_tor_control_connection, tor_control_reply);
78
});
79
}
80
}
FuzzedDataProvider.h
DummyTorControlConnection
Definition
torcontrol.cpp:16
DummyTorControlConnection::Command
bool Command(const std::string &, const ReplyHandlerCB &)
Definition
torcontrol.cpp:31
DummyTorControlConnection::Connect
bool Connect(const std::string &, const ConnectionCB &, const ConnectionCB &)
Definition
torcontrol.cpp:22
DummyTorControlConnection::DummyTorControlConnection
DummyTorControlConnection()
Definition
torcontrol.cpp:18
DummyTorControlConnection::Disconnect
void Disconnect()
Definition
torcontrol.cpp:27
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition
FuzzedDataProvider.h:195
TorControlConnection::TorControlConnection
TorControlConnection(struct event_base *base)
Create a new TorControlConnection.
Definition
torcontrol.cpp:77
TorControlConnection::ReplyHandlerCB
std::function< void(TorControlConnection &, const TorControlReply &)> ReplyHandlerCB
Definition
torcontrol.h:56
TorControlConnection::ConnectionCB
std::function< void(TorControlConnection &)> ConnectionCB
Definition
torcontrol.h:55
TorControlReply
Reply from Tor, can be single or multi-line.
Definition
torcontrol.h:35
TorControlReply::code
int code
Definition
torcontrol.h:39
TorControlReply::lines
std::vector< std::string > lines
Definition
torcontrol.h:40
TorController
Controller that connects to Tor control socket, authenticate, then create and maintain an ephemeral o...
Definition
torcontrol.h:108
TorController::add_onion_cb
void add_onion_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for ADD_ONION result.
Definition
torcontrol.cpp:429
TorController::authchallenge_cb
void authchallenge_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for AUTHCHALLENGE result.
Definition
torcontrol.cpp:515
TorController::auth_cb
void auth_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for AUTHENTICATE result.
Definition
torcontrol.cpp:464
TorController::protocolinfo_cb
void protocolinfo_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for PROTOCOLINFO result.
Definition
torcontrol.cpp:550
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
bitcoin-gui.cpp:17
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:250
initialize_torcontrol
void initialize_torcontrol()
Definition
torcontrol.cpp:37
util.h
CallOneOf
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition
util.h:35
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:73
torcontrol.h
Generated on
for Bitcoin Core by
1.17.0