Bitcoin Core 28.99.0
P2P Digital Currency
socks5.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-2022 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 <netaddress.h>
6#include <netbase.h>
8#include <test/fuzz/fuzz.h>
9#include <test/fuzz/util.h>
10#include <test/fuzz/util/net.h>
12
13#include <cstdint>
14#include <string>
15#include <vector>
16
17extern std::chrono::milliseconds g_socks5_recv_timeout;
18
19namespace {
20decltype(g_socks5_recv_timeout) default_socks5_recv_timeout;
21};
22
24{
25 static const auto testing_setup = MakeNoLogFileContext<const BasicTestingSetup>();
26 default_socks5_recv_timeout = g_socks5_recv_timeout;
27}
28
30{
31 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
32 ProxyCredentials proxy_credentials;
33 proxy_credentials.username = fuzzed_data_provider.ConsumeRandomLengthString(512);
34 proxy_credentials.password = fuzzed_data_provider.ConsumeRandomLengthString(512);
35 if (fuzzed_data_provider.ConsumeBool()) {
37 }
38 // Set FUZZED_SOCKET_FAKE_LATENCY=1 to exercise recv timeout code paths. This
39 // will slow down fuzzing.
40 g_socks5_recv_timeout = (fuzzed_data_provider.ConsumeBool() && std::getenv("FUZZED_SOCKET_FAKE_LATENCY") != nullptr) ? 1ms : default_socks5_recv_timeout;
41 FuzzedSock fuzzed_sock = ConsumeSock(fuzzed_data_provider);
42 // This Socks5(...) fuzzing harness would have caught CVE-2017-18350 within
43 // a few seconds of fuzzing.
44 auto str_dest = fuzzed_data_provider.ConsumeRandomLengthString(512);
45 auto port = fuzzed_data_provider.ConsumeIntegral<uint16_t>();
46 auto* auth = fuzzed_data_provider.ConsumeBool() ? &proxy_credentials : nullptr;
47 (void)Socks5(str_dest, port, auth, fuzzed_sock);
48}
CThreadInterrupt g_socks5_interrupt
Interrupt SOCKS5 reads or writes.
Definition: netbase.cpp:41
bool Socks5(const std::string &strDest, uint16_t port, const ProxyCredentials *auth, const Sock &sock)
Connect to a specified destination service through an already connected SOCKS5 proxy.
Definition: netbase.cpp:372
std::chrono::milliseconds g_socks5_recv_timeout
Definition: netbase.cpp:40
void initialize_socks5()
Definition: socks5.cpp:23
FUZZ_TARGET(socks5,.init=initialize_socks5)
Definition: socks5.cpp:29
Credentials for proxy authentication.
Definition: netbase.h:93
std::string username
Definition: netbase.h:94
std::string password
Definition: netbase.h:95
FuzzedSock ConsumeSock(FuzzedDataProvider &fuzzed_data_provider)
Definition: net.h:196