mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-12 15:03:18 +02:00
Gets rid of the Dummy class and adds coverage of get_socks_cb. Also explicitly handles an exception case within Torcontrol rather than relying on a guard in the fuzz test.
68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
// Copyright (c) 2020-present 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 <test/util/setup_common.h>
|
|
#include <torcontrol.h>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
void initialize_torcontrol()
|
|
{
|
|
static const auto testing_setup = MakeNoLogFileContext<>();
|
|
}
|
|
|
|
FUZZ_TARGET(torcontrol, .init = initialize_torcontrol)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
|
|
|
TorController tor_controller;
|
|
CThreadInterrupt interrupt;
|
|
TorControlConnection conn{interrupt};
|
|
|
|
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
|
|
TorControlReply tor_control_reply;
|
|
CallOneOf(
|
|
fuzzed_data_provider,
|
|
[&] {
|
|
tor_control_reply.code = TOR_REPLY_OK;
|
|
},
|
|
[&] {
|
|
tor_control_reply.code = TOR_REPLY_UNRECOGNIZED;
|
|
},
|
|
[&] {
|
|
tor_control_reply.code = TOR_REPLY_SYNTAX_ERROR;
|
|
},
|
|
[&] {
|
|
tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
|
|
});
|
|
tor_control_reply.lines = ConsumeRandomLengthStringVector(fuzzed_data_provider);
|
|
|
|
CallOneOf(
|
|
fuzzed_data_provider,
|
|
[&] {
|
|
tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/true);
|
|
},
|
|
[&] {
|
|
tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/false);
|
|
},
|
|
[&] {
|
|
tor_controller.auth_cb(conn, tor_control_reply);
|
|
},
|
|
[&] {
|
|
tor_controller.authchallenge_cb(conn, tor_control_reply);
|
|
},
|
|
[&] {
|
|
tor_controller.protocolinfo_cb(conn, tor_control_reply);
|
|
},
|
|
[&] {
|
|
tor_controller.get_socks_cb(conn, tor_control_reply);
|
|
});
|
|
}
|
|
}
|