Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.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 <test/util/time.h>13#include <util/time.h>15#include <cstdint>16#include <string>17#include <vector>19extern std::chrono::milliseconds g_socks5_recv_timeout;21namespace {22decltype(g_socks5_recv_timeout) default_socks5_recv_timeout;23};25void initialize_socks5()26{27static const auto testing_setup = MakeNoLogFileContext<const BasicTestingSetup>();28default_socks5_recv_timeout = g_socks5_recv_timeout;29}31FUZZ_TARGET(socks5, .init = initialize_socks5)32{33g_socks5_interrupt.reset();34FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};35FakeNodeClock clock{ConsumeTime(fuzzed_data_provider)};36FakeSteadyClock steady_clock;37ProxyCredentials proxy_credentials;38proxy_credentials.username = fuzzed_data_provider.ConsumeRandomLengthString(512);39proxy_credentials.password = fuzzed_data_provider.ConsumeRandomLengthString(512);40if (fuzzed_data_provider.ConsumeBool()) {41g_socks5_interrupt();42}43// Set FUZZED_SOCKET_FAKE_LATENCY=1 to exercise recv timeout code paths. This44// will slow down fuzzing.45g_socks5_recv_timeout = (fuzzed_data_provider.ConsumeBool() && std::getenv("FUZZED_SOCKET_FAKE_LATENCY") != nullptr) ? 1ms : default_socks5_recv_timeout;46FuzzedSock fuzzed_sock = ConsumeSock(fuzzed_data_provider, steady_clock);47// This Socks5(...) fuzzing harness would have caught CVE-2017-18350 within48// a few seconds of fuzzing.49auto str_dest = fuzzed_data_provider.ConsumeRandomLengthString(512);50auto port = fuzzed_data_provider.ConsumeIntegral<uint16_t>();51auto* auth = fuzzed_data_provider.ConsumeBool() ? &proxy_credentials : nullptr;52(void)Socks5(str_dest, port, auth, fuzzed_sock);53}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.