mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 01:42:58 +01:00
addrman: cap the max_pct
to not exceed the maximum number of addresses
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
This commit is contained in:
parent
2c90f8e08c
commit
9c5775c331
@ -812,9 +812,11 @@ nid_type AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) c
|
||||
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
Assume(max_pct <= 100);
|
||||
|
||||
size_t nNodes = vRandom.size();
|
||||
if (max_pct != 0) {
|
||||
max_pct = std::min(max_pct, size_t{100});
|
||||
nNodes = max_pct * nNodes / 100;
|
||||
}
|
||||
if (max_addresses != 0) {
|
||||
|
@ -166,7 +166,7 @@ public:
|
||||
* Return all or many randomly selected addresses, optionally by network.
|
||||
*
|
||||
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
|
||||
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
|
||||
* @param[in] max_pct Maximum percentage of addresses to return (0 = all). Value must be from 0 to 100.
|
||||
* @param[in] network Select only addresses of this network (nullopt = all).
|
||||
* @param[in] filtered Select only addresses that are considered good quality (false = all).
|
||||
*
|
||||
|
@ -1152,7 +1152,7 @@ public:
|
||||
* Return all or many randomly selected addresses, optionally by network.
|
||||
*
|
||||
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
|
||||
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
|
||||
* @param[in] max_pct Maximum percentage of addresses to return (0 = all). Value must be from 0 to 100.
|
||||
* @param[in] network Select only addresses of this network (nullopt = all).
|
||||
* @param[in] filtered Select only addresses that are considered high quality (false = all).
|
||||
*/
|
||||
|
@ -173,7 +173,7 @@ FUZZ_TARGET(addrman, .init = initialize_addrman)
|
||||
network = fuzzed_data_provider.PickValueInArray(ALL_NETWORKS);
|
||||
}
|
||||
auto max_addresses = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096);
|
||||
auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096);
|
||||
auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 100);
|
||||
auto filtered = fuzzed_data_provider.ConsumeBool();
|
||||
(void)const_addr_man.GetAddr(max_addresses, max_pct, network, filtered);
|
||||
|
||||
|
@ -110,13 +110,13 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
||||
},
|
||||
[&] {
|
||||
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||
auto max_pct = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||
auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 100);
|
||||
auto filtered = fuzzed_data_provider.ConsumeBool();
|
||||
(void)connman.GetAddresses(max_addresses, max_pct, /*network=*/std::nullopt, filtered);
|
||||
},
|
||||
[&] {
|
||||
auto max_addresses = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||
auto max_pct = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||
auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 100);
|
||||
(void)connman.GetAddresses(/*requestor=*/random_node, max_addresses, max_pct);
|
||||
},
|
||||
[&] {
|
||||
|
Loading…
Reference in New Issue
Block a user