mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
merge bitcoin#26497: Make ConsumeNetAddr always produce valid onion addresses
This commit is contained in:
parent
6a37934af4
commit
291305b4d2
@ -11,7 +11,8 @@ TEST_FUZZ_H = \
|
||||
test/fuzz/fuzz.h \
|
||||
test/fuzz/FuzzedDataProvider.h \
|
||||
test/fuzz/util.h \
|
||||
test/util/mining.h
|
||||
test/util/mining.h \
|
||||
test/fuzz/util/net.h
|
||||
|
||||
libtest_fuzz_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
|
||||
libtest_fuzz_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
@ -19,6 +20,7 @@ libtest_fuzz_a_SOURCES = \
|
||||
test/fuzz/fuzz.cpp \
|
||||
test/util/mining.cpp \
|
||||
test/fuzz/util.cpp \
|
||||
test/fuzz/util/net.cpp \
|
||||
$(TEST_FUZZ_H)
|
||||
|
||||
LIBTEST_FUZZ += $(LIBBITCOIN_SERVER)
|
||||
|
@ -598,7 +598,7 @@ static std::string IPv6ToString(Span<const uint8_t> a, uint32_t scope_id)
|
||||
return r;
|
||||
}
|
||||
|
||||
static std::string OnionToString(Span<const uint8_t> addr)
|
||||
std::string OnionToString(Span<const uint8_t> addr)
|
||||
{
|
||||
uint8_t checksum[torv3::CHECKSUM_LEN];
|
||||
torv3::Checksum(addr, checksum);
|
||||
|
@ -113,6 +113,8 @@ static constexpr size_t ADDR_INTERNAL_SIZE = 10;
|
||||
/// SAM 3.1 and earlier do not support specifying ports and force the port to 0.
|
||||
static constexpr uint16_t I2P_SAM31_PORT{0};
|
||||
|
||||
std::string OnionToString(Span<const uint8_t> addr);
|
||||
|
||||
/**
|
||||
* Network address.
|
||||
*/
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/fuzz/util/net.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <time.h>
|
||||
#include <util/asmap.h>
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/fuzz/util/net.h>
|
||||
#include <util/readwritefile.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/system.h>
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/fuzz/util/net.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <netaddress.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/fuzz/util/net.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <netbase.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/fuzz/util/net.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <net_processing.h>
|
||||
#include <netaddress.h>
|
||||
#include <netmessagemaker.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/util/script.h>
|
||||
@ -389,28 +390,6 @@ bool ContainsSpentInput(const CTransaction& tx, const CCoinsViewCache& inputs) n
|
||||
return false;
|
||||
}
|
||||
|
||||
CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
const Network network = fuzzed_data_provider.PickValueInArray({Network::NET_IPV4, Network::NET_IPV6, Network::NET_INTERNAL, Network::NET_ONION});
|
||||
CNetAddr net_addr;
|
||||
if (network == Network::NET_IPV4) {
|
||||
in_addr v4_addr = {};
|
||||
v4_addr.s_addr = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
|
||||
net_addr = CNetAddr{v4_addr};
|
||||
} else if (network == Network::NET_IPV6) {
|
||||
if (fuzzed_data_provider.remaining_bytes() >= 16) {
|
||||
in6_addr v6_addr = {};
|
||||
memcpy(v6_addr.s6_addr, fuzzed_data_provider.ConsumeBytes<uint8_t>(16).data(), 16);
|
||||
net_addr = CNetAddr{v6_addr, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
|
||||
}
|
||||
} else if (network == Network::NET_INTERNAL) {
|
||||
net_addr.SetInternal(fuzzed_data_provider.ConsumeBytesAsString(32));
|
||||
} else if (network == Network::NET_ONION) {
|
||||
net_addr.SetSpecial(fuzzed_data_provider.ConsumeBytesAsString(32));
|
||||
}
|
||||
return net_addr;
|
||||
}
|
||||
|
||||
FILE* FuzzedFileProvider::open()
|
||||
{
|
||||
SetFuzzedErrNo(m_fuzzed_data_provider);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <streams.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util/net.h>
|
||||
#include <test/util/net.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <txmempool.h>
|
||||
@ -296,8 +297,6 @@ template<typename B = uint8_t>
|
||||
return random_bytes;
|
||||
}
|
||||
|
||||
CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||
|
||||
inline CSubNet ConsumeSubNet(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
return {ConsumeNetAddr(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<uint8_t>()};
|
||||
|
36
src/test/fuzz/util/net.cpp
Normal file
36
src/test/fuzz/util/net.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2009-2021 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 <compat.h>
|
||||
#include <netaddress.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
const Network network = fuzzed_data_provider.PickValueInArray({Network::NET_IPV4, Network::NET_IPV6, Network::NET_INTERNAL, Network::NET_ONION});
|
||||
CNetAddr net_addr;
|
||||
if (network == Network::NET_IPV4) {
|
||||
in_addr v4_addr = {};
|
||||
v4_addr.s_addr = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
|
||||
net_addr = CNetAddr{v4_addr};
|
||||
} else if (network == Network::NET_IPV6) {
|
||||
if (fuzzed_data_provider.remaining_bytes() >= 16) {
|
||||
in6_addr v6_addr = {};
|
||||
memcpy(v6_addr.s6_addr, fuzzed_data_provider.ConsumeBytes<uint8_t>(16).data(), 16);
|
||||
net_addr = CNetAddr{v6_addr, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
|
||||
}
|
||||
} else if (network == Network::NET_INTERNAL) {
|
||||
net_addr.SetInternal(fuzzed_data_provider.ConsumeBytesAsString(32));
|
||||
} else if (network == Network::NET_ONION) {
|
||||
auto pub_key{fuzzed_data_provider.ConsumeBytes<uint8_t>(ADDR_TORV3_SIZE)};
|
||||
pub_key.resize(ADDR_TORV3_SIZE);
|
||||
const bool ok{net_addr.SetSpecial(OnionToString(pub_key))};
|
||||
assert(ok);
|
||||
}
|
||||
return net_addr;
|
||||
}
|
14
src/test/fuzz/util/net.h
Normal file
14
src/test/fuzz/util/net.h
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2009-2021 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_TEST_FUZZ_UTIL_NET_H
|
||||
#define BITCOIN_TEST_FUZZ_UTIL_NET_H
|
||||
|
||||
#include <netaddress.h>
|
||||
|
||||
class FuzzedDataProvider;
|
||||
|
||||
CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||
|
||||
#endif // BITCOIN_TEST_FUZZ_UTIL_NET_H
|
Loading…
Reference in New Issue
Block a user