Skip to content

Commit e5a7dfd

Browse files
p2p: rename GetAddresses -> GetAddressesUnsafe
Rename GetAddresses to GetAddressesUnsafe to make it clearer that this function should only be used in trusted contexts. This helps avoid accidental privacy leaks by preventing the uncached version from being used in non-trusted scenarios, like P2P.
1 parent 184159e commit e5a7dfd

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/net.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,7 @@ CConnman::~CConnman()
34963496
Stop();
34973497
}
34983498

3499-
std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
3499+
std::vector<CAddress> CConnman::GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
35003500
{
35013501
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct, network, filtered);
35023502
if (m_banman) {
@@ -3521,7 +3521,7 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
35213521
auto r = m_addr_response_caches.emplace(cache_id, CachedAddrResponse{});
35223522
CachedAddrResponse& cache_entry = r.first->second;
35233523
if (cache_entry.m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
3524-
cache_entry.m_addrs_response_cache = GetAddresses(max_addresses, max_pct, /*network=*/std::nullopt);
3524+
cache_entry.m_addrs_response_cache = GetAddressesUnsafe(max_addresses, max_pct, /*network=*/std::nullopt);
35253525
// Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
35263526
// and the usefulness of ADDR responses to honest users.
35273527
//
@@ -3964,8 +3964,8 @@ void CConnman::PerformReconnections()
39643964

39653965
void CConnman::ASMapHealthCheck()
39663966
{
3967-
const std::vector<CAddress> v4_addrs{GetAddresses(/*max_addresses=*/ 0, /*max_pct=*/ 0, Network::NET_IPV4, /*filtered=*/ false)};
3968-
const std::vector<CAddress> v6_addrs{GetAddresses(/*max_addresses=*/ 0, /*max_pct=*/ 0, Network::NET_IPV6, /*filtered=*/ false)};
3967+
const std::vector<CAddress> v4_addrs{GetAddressesUnsafe(/*max_addresses=*/0, /*max_pct=*/0, Network::NET_IPV4, /*filtered=*/false)};
3968+
const std::vector<CAddress> v6_addrs{GetAddressesUnsafe(/*max_addresses=*/0, /*max_pct=*/0, Network::NET_IPV6, /*filtered=*/false)};
39693969
std::vector<CNetAddr> clearnet_addrs;
39703970
clearnet_addrs.reserve(v4_addrs.size() + v6_addrs.size());
39713971
std::transform(v4_addrs.begin(), v4_addrs.end(), std::back_inserter(clearnet_addrs),

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ class CConnman
11761176
* @param[in] network Select only addresses of this network (nullopt = all).
11771177
* @param[in] filtered Select only addresses that are considered high quality (false = all).
11781178
*/
1179-
std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
1179+
std::vector<CAddress> GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
11801180
/**
11811181
* Cache is used to minimize topology leaks, so it should
11821182
* be used for all non-trusted calls, for example, p2p.

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4715,7 +4715,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
47154715
peer->m_addrs_to_send.clear();
47164716
std::vector<CAddress> vAddr;
47174717
if (pfrom.HasPermission(NetPermissionFlags::Addr)) {
4718-
vAddr = m_connman.GetAddresses(MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND, /*network=*/std::nullopt);
4718+
vAddr = m_connman.GetAddressesUnsafe(MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND, /*network=*/std::nullopt);
47194719
} else {
47204720
vAddr = m_connman.GetAddresses(pfrom, MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND);
47214721
}

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ static RPCHelpMan getnodeaddresses()
953953
}
954954

955955
// returns a shuffled list of CAddress
956-
const std::vector<CAddress> vAddr{connman.GetAddresses(count, /*max_pct=*/0, network)};
956+
const std::vector<CAddress> vAddr{connman.GetAddressesUnsafe(count, /*max_pct=*/0, network)};
957957
UniValue ret(UniValue::VARR);
958958

959959
for (const CAddress& addr : vAddr) {

src/test/fuzz/connman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
113113
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();
114114
auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 100);
115115
auto filtered = fuzzed_data_provider.ConsumeBool();
116-
(void)connman.GetAddresses(max_addresses, max_pct, /*network=*/std::nullopt, filtered);
116+
(void)connman.GetAddressesUnsafe(max_addresses, max_pct, /*network=*/std::nullopt, filtered);
117117
},
118118
[&] {
119119
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();

0 commit comments

Comments
 (0)