Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
socks5.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 <
netaddress.h
>
6
#include <
netbase.h
>
7
#include <
test/fuzz/FuzzedDataProvider.h
>
8
#include <
test/fuzz/fuzz.h
>
9
#include <
test/fuzz/util.h
>
10
#include <
test/fuzz/util/net.h
>
11
#include <
test/util/setup_common.h
>
12
#include <util/time.h>
13
14
#include <cstdint>
15
#include <string>
16
#include <vector>
17
18
extern
std::chrono::milliseconds
g_socks5_recv_timeout
;
19
20
namespace
{
21
decltype
(
g_socks5_recv_timeout
) default_socks5_recv_timeout;
22
};
23
24
void
initialize_socks5
()
25
{
26
static
const
auto
testing_setup =
MakeNoLogFileContext<const BasicTestingSetup>
();
27
default_socks5_recv_timeout =
g_socks5_recv_timeout
;
28
}
29
30
FUZZ_TARGET
(socks5, .
init
=
initialize_socks5
)
31
{
32
FuzzedDataProvider
fuzzed_data_provider{buffer.data(), buffer.size()};
33
SetMockTime
(
ConsumeTime
(fuzzed_data_provider));
34
ProxyCredentials
proxy_credentials;
35
proxy_credentials.
username
= fuzzed_data_provider.
ConsumeRandomLengthString
(512);
36
proxy_credentials.
password
= fuzzed_data_provider.
ConsumeRandomLengthString
(512);
37
if
(fuzzed_data_provider.
ConsumeBool
()) {
38
g_socks5_interrupt
();
39
}
40
// Set FUZZED_SOCKET_FAKE_LATENCY=1 to exercise recv timeout code paths. This
41
// will slow down fuzzing.
42
g_socks5_recv_timeout
= (fuzzed_data_provider.
ConsumeBool
() && std::getenv(
"FUZZED_SOCKET_FAKE_LATENCY"
) !=
nullptr
) ? 1ms : default_socks5_recv_timeout;
43
FuzzedSock
fuzzed_sock =
ConsumeSock
(fuzzed_data_provider);
44
// This Socks5(...) fuzzing harness would have caught CVE-2017-18350 within
45
// a few seconds of fuzzing.
46
auto
str_dest = fuzzed_data_provider.
ConsumeRandomLengthString
(512);
47
auto
port = fuzzed_data_provider.
ConsumeIntegral
<uint16_t>();
48
auto
* auth = fuzzed_data_provider.
ConsumeBool
() ? &proxy_credentials :
nullptr
;
49
(void)
Socks5
(str_dest, port, auth, fuzzed_sock);
50
}
FuzzedDataProvider.h
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeRandomLengthString
std::string ConsumeRandomLengthString(size_t max_length)
Definition
FuzzedDataProvider.h:153
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition
FuzzedDataProvider.h:195
FuzzedSock
Definition
net.h:163
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
init
Definition
bitcoin-gui.cpp:17
netaddress.h
g_socks5_recv_timeout
std::chrono::milliseconds g_socks5_recv_timeout
Definition
netbase.cpp:40
g_socks5_interrupt
CThreadInterrupt g_socks5_interrupt
Interrupt SOCKS5 reads or writes.
Definition
netbase.cpp:41
Socks5
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:392
netbase.h
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_socks5
void initialize_socks5()
Definition
socks5.cpp:24
ProxyCredentials
Credentials for proxy authentication.
Definition
netbase.h:94
ProxyCredentials::username
std::string username
Definition
netbase.h:95
ProxyCredentials::password
std::string password
Definition
netbase.h:96
net.h
ConsumeSock
FuzzedSock ConsumeSock(FuzzedDataProvider &fuzzed_data_provider)
Definition
net.h:231
ConsumeTime
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition
util.cpp:34
util.h
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition
time.cpp:44
Generated on
for Bitcoin Core by
1.17.0