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.
This commit is contained in:
5 files changed
+8
-8
No files matched your search
+4
-4
@@ -3496,7 +3496,7 @@ CConnman::~CConnman()
|
|||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
|
std::vector<CAddress> CConnman::GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
|
||||||
{
|
{
|
||||||
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct, network, filtered);
|
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct, network, filtered);
|
||||||
if (m_banman) {
|
if (m_banman) {
|
||||||
@@ -3521,7 +3521,7 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
|
|||||||
auto r = m_addr_response_caches.emplace(cache_id, CachedAddrResponse{});
|
auto r = m_addr_response_caches.emplace(cache_id, CachedAddrResponse{});
|
||||||
CachedAddrResponse& cache_entry = r.first->second;
|
CachedAddrResponse& cache_entry = r.first->second;
|
||||||
if (cache_entry.m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
|
if (cache_entry.m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
|
||||||
cache_entry.m_addrs_response_cache = GetAddresses(max_addresses, max_pct, /*network=*/std::nullopt);
|
cache_entry.m_addrs_response_cache = GetAddressesUnsafe(max_addresses, max_pct, /*network=*/std::nullopt);
|
||||||
// Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
|
// Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
|
||||||
// and the usefulness of ADDR responses to honest users.
|
// and the usefulness of ADDR responses to honest users.
|
||||||
//
|
//
|
||||||
@@ -3964,8 +3964,8 @@ void CConnman::PerformReconnections()
|
|||||||
|
|
||||||
void CConnman::ASMapHealthCheck()
|
void CConnman::ASMapHealthCheck()
|
||||||
{
|
{
|
||||||
const std::vector<CAddress> v4_addrs{GetAddresses(/*max_addresses=*/ 0, /*max_pct=*/ 0, Network::NET_IPV4, /*filtered=*/ false)};
|
const std::vector<CAddress> v4_addrs{GetAddressesUnsafe(/*max_addresses=*/0, /*max_pct=*/0, Network::NET_IPV4, /*filtered=*/false)};
|
||||||
const std::vector<CAddress> v6_addrs{GetAddresses(/*max_addresses=*/ 0, /*max_pct=*/ 0, Network::NET_IPV6, /*filtered=*/ false)};
|
const std::vector<CAddress> v6_addrs{GetAddressesUnsafe(/*max_addresses=*/0, /*max_pct=*/0, Network::NET_IPV6, /*filtered=*/false)};
|
||||||
std::vector<CNetAddr> clearnet_addrs;
|
std::vector<CNetAddr> clearnet_addrs;
|
||||||
clearnet_addrs.reserve(v4_addrs.size() + v6_addrs.size());
|
clearnet_addrs.reserve(v4_addrs.size() + v6_addrs.size());
|
||||||
std::transform(v4_addrs.begin(), v4_addrs.end(), std::back_inserter(clearnet_addrs),
|
std::transform(v4_addrs.begin(), v4_addrs.end(), std::back_inserter(clearnet_addrs),
|
||||||
|
|||||||
@@ -1176,7 +1176,7 @@ public:
|
|||||||
* @param[in] network Select only addresses of this network (nullopt = all).
|
* @param[in] network Select only addresses of this network (nullopt = all).
|
||||||
* @param[in] filtered Select only addresses that are considered high quality (false = all).
|
* @param[in] filtered Select only addresses that are considered high quality (false = all).
|
||||||
*/
|
*/
|
||||||
std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
|
std::vector<CAddress> GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
|
||||||
/**
|
/**
|
||||||
* Cache is used to minimize topology leaks, so it should
|
* Cache is used to minimize topology leaks, so it should
|
||||||
* be used for all non-trusted calls, for example, p2p.
|
* be used for all non-trusted calls, for example, p2p.
|
||||||
|
|||||||
@@ -4715,7 +4715,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
peer->m_addrs_to_send.clear();
|
peer->m_addrs_to_send.clear();
|
||||||
std::vector<CAddress> vAddr;
|
std::vector<CAddress> vAddr;
|
||||||
if (pfrom.HasPermission(NetPermissionFlags::Addr)) {
|
if (pfrom.HasPermission(NetPermissionFlags::Addr)) {
|
||||||
vAddr = m_connman.GetAddresses(MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND, /*network=*/std::nullopt);
|
vAddr = m_connman.GetAddressesUnsafe(MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND, /*network=*/std::nullopt);
|
||||||
} else {
|
} else {
|
||||||
vAddr = m_connman.GetAddresses(pfrom, MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND);
|
vAddr = m_connman.GetAddresses(pfrom, MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -953,7 +953,7 @@ static RPCHelpMan getnodeaddresses()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns a shuffled list of CAddress
|
// returns a shuffled list of CAddress
|
||||||
const std::vector<CAddress> vAddr{connman.GetAddresses(count, /*max_pct=*/0, network)};
|
const std::vector<CAddress> vAddr{connman.GetAddressesUnsafe(count, /*max_pct=*/0, network)};
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
|
|
||||||
for (const CAddress& addr : vAddr) {
|
for (const CAddress& addr : vAddr) {
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
|||||||
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||||
auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 100);
|
auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 100);
|
||||||
auto filtered = fuzzed_data_provider.ConsumeBool();
|
auto filtered = fuzzed_data_provider.ConsumeBool();
|
||||||
(void)connman.GetAddresses(max_addresses, max_pct, /*network=*/std::nullopt, filtered);
|
(void)connman.GetAddressesUnsafe(max_addresses, max_pct, /*network=*/std::nullopt, filtered);
|
||||||
},
|
},
|
||||||
[&] {
|
[&] {
|
||||||
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||||
|
|||||||
Reference in new issue
Block a user