Merge #19288: fuzz: Add fuzzing harness for TorController
pull/826/head10d4477dae
tests: Add fuzzing harness for TorController (practicalswift)64219c01dc
torcontrol: Move TorControlReply, TorControlConnection and TorController to improve testability (practicalswift) Pull request description: Add fuzzing harness for `TorController`. See [`doc/fuzzing.md`](https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md) for information on how to fuzz Bitcoin Core. Don't forget to contribute any coverage increasing inputs you find to the [Bitcoin Core fuzzing corpus repo](https://github.com/bitcoin-core/qa-assets). Happy fuzzing :) ACKs for top commit: laanwj: ACK10d4477dae
Tree-SHA512: 2da4b1000afe0e65a234636b8fbf6a26fe9e257852bd837168ca73aa3575959e9aded19054620439e4ed0b2787c70cad4541a8c2d210f5238d7f5e9e0545b734
commit
dd8f474d52
@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <torcontrol.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class DummyTorControlConnection : public TorControlConnection
|
||||
{
|
||||
public:
|
||||
DummyTorControlConnection() : TorControlConnection{nullptr}
|
||||
{
|
||||
}
|
||||
|
||||
bool Connect(const std::string&, const ConnectionCB&, const ConnectionCB&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Disconnect()
|
||||
{
|
||||
}
|
||||
|
||||
bool Command(const std::string&, const ReplyHandlerCB&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void initialize_torcontrol()
|
||||
{
|
||||
static const auto testing_setup = MakeNoLogFileContext<>();
|
||||
}
|
||||
|
||||
FUZZ_TARGET_INIT(torcontrol, initialize_torcontrol)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
|
||||
TorController tor_controller;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
TorControlReply tor_control_reply;
|
||||
CallOneOf(
|
||||
fuzzed_data_provider,
|
||||
[&] {
|
||||
tor_control_reply.code = 250;
|
||||
},
|
||||
[&] {
|
||||
tor_control_reply.code = 510;
|
||||
},
|
||||
[&] {
|
||||
tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
|
||||
});
|
||||
tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider);
|
||||
if (tor_control_reply.lines.empty()) {
|
||||
break;
|
||||
}
|
||||
DummyTorControlConnection dummy_tor_control_connection;
|
||||
CallOneOf(
|
||||
fuzzed_data_provider,
|
||||
[&] {
|
||||
tor_controller.add_onion_cb(dummy_tor_control_connection, tor_control_reply);
|
||||
},
|
||||
[&] {
|
||||
tor_controller.auth_cb(dummy_tor_control_connection, tor_control_reply);
|
||||
},
|
||||
[&] {
|
||||
tor_controller.authchallenge_cb(dummy_tor_control_connection, tor_control_reply);
|
||||
},
|
||||
[&] {
|
||||
tor_controller.protocolinfo_cb(dummy_tor_control_connection, tor_control_reply);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in new issue