Skip to content

Commit d75a1df

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#21941: fuzz: Call const member functions in addrman fuzz test only once
faf7623 fuzz: Call const member functions in addrman fuzz test only once (MarcoFalke) Pull request description: Logically based on #21940 Currently the fuzz test may spend a long time generating random numbers: ![Screenshot from 2021-05-13 12-14-09](https://user-images.githubusercontent.com/6399679/118112238-06ecd880-b3e5-11eb-8013-6e0c20e6159f.png) Fix that by calling const member functions only once. Hopefully fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34224 ACKs for top commit: practicalswift: cr ACK faf7623: touches only `src/test/fuzz/addrman.cpp` Tree-SHA512: 0fe9e0111eb1706fc39bd2f90d4b87a771882bada54c01e96d8e79c2afca2f1081139d5ab680285a81835cc5142e74ada422a181db34b01904975d1e167e64c2
2 parents 964d91b + faf7623 commit d75a1df

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/test/fuzz/addrman.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
5656
[&] {
5757
(void)addr_man.SelectTriedCollision();
5858
},
59-
[&] {
60-
(void)addr_man.Select(fuzzed_data_provider.ConsumeBool());
61-
},
62-
[&] {
63-
(void)addr_man.GetAddr(
64-
/* max_addresses */ fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
65-
/* max_pct */ fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
66-
/* network */ std::nullopt);
67-
},
6859
[&] {
6960
const std::optional<CAddress> opt_address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
7061
const std::optional<CNetAddr> opt_net_addr = ConsumeDeserializable<CNetAddr>(fuzzed_data_provider);
@@ -109,12 +100,16 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
109100
if (opt_service) {
110101
addr_man.SetServices(*opt_service, ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS));
111102
}
112-
},
113-
[&] {
114-
(void)addr_man.Check();
115103
});
116104
}
117-
(void)addr_man.size();
105+
const CAddrMan& const_addr_man{addr_man};
106+
(void)/*const_*/addr_man.GetAddr(
107+
/* max_addresses */ fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
108+
/* max_pct */ fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
109+
/* network */ std::nullopt);
110+
(void)/*const_*/addr_man.Check();
111+
(void)/*const_*/addr_man.Select(fuzzed_data_provider.ConsumeBool());
112+
(void)const_addr_man.size();
118113
CDataStream data_stream(SER_NETWORK, PROTOCOL_VERSION);
119-
data_stream << addr_man;
114+
data_stream << const_addr_man;
120115
}

0 commit comments

Comments
 (0)