network
field in Select()
, Size()
and GetAddr()
, there was only call to them without passing a network.
https://marcofalke.github.io/b-c-cov/fuzz.coverage/src/addrman.cpp.gcov.html
network
field in Select()
, Size()
and GetAddr()
#27549
network
field in Select()
, Size()
and GetAddr()
, there was only call to them without passing a network.
https://marcofalke.github.io/b-c-cov/fuzz.coverage/src/addrman.cpp.gcov.html
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
See the guideline for information on the review process.
Type | Reviewers |
---|---|
ACK | amitiuttarwar, mzumsande, achow101 |
Concept ACK | pablomartin4btc |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
302@@ -303,6 +303,8 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
303 /*max_addresses=*/fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
304 /*max_pct=*/fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
305 /*network=*/std::nullopt);
306+ const std::optional<Network> network{fuzzed_data_provider.PickValueInArray({Network::NET_IPV4, Network::NET_IPV6, Network::NET_INTERNAL, Network::NET_ONION, Network::NET_I2P})};
ALL_NETWORKS
?
test/fuzz/util/net.h
there is no reason, gonna change it!
GetAddr()
, Size()
). I think it’s fine to do it in a separate PR too, but while at it, it would be good to also add coverage for these other functions.
Co-authored-by: Amiti Uttarwar <amiti@uttarwar.org>
Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
Force-pushed addressing #27549#pullrequestreview-1408940288
Added coverage for Size()
and GetAddr()
, since I got code from https://github.com/bitcoin/bitcoin/commit/8f91e5898b3571e0802f2197981c54dda9ee71fa, I added @mzumsande and @amitiuttarwar as co-authors. PR description has been updated.
312+ network);
313+ (void)const_addr_man.Select(fuzzed_data_provider.ConsumeBool(), network);
314+ std::optional<bool> in_new;
315+ if (fuzzed_data_provider.ConsumeBool()) {
316+ in_new = fuzzed_data_provider.ConsumeBool();
317+ }
I was going to propose:
0 bool in_new{fuzzed_data_provider.ConsumeBool()};
But then I checked also the definition of theAddrMan::Size()
function consuming in_new
as and argument and I see in the comments that it would interpret the 3 states:
0/**
1 * Return size information about addrman.
2 *
3 * [@param](/bitcoin-bitcoin/contributor/param/)[in] net Select addresses only from specified network (nullopt = all)
4 * [@param](/bitcoin-bitcoin/contributor/param/)[in] in_new Select addresses only from one table (true = new, false = tried, nullopt = both)
5 * [@return](/bitcoin-bitcoin/contributor/return/) Number of unique addresses that match specified options.
6 */
edit: just thinking, we never use the false
alternative here (tried table), perhaps this is not an issue.
298@@ -299,12 +299,20 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
299 });
300 }
301 const AddrMan& const_addr_man{addr_man};
302+ std::optional<Network> network;
303+ if (fuzzed_data_provider.ConsumeBool()) {
304+ network = fuzzed_data_provider.PickValueInArray(ALL_NETWORKS);
305+ }
Do we really need this?
Next line calling AddrMan::GetAddr()
function passes std::nullopt
as the network argument (meaning ALL_NETWORKS), so as AddrMan::Size()
also interprets the same for the network argument and since even ConsumesBool()
when returns false it would be std::nullopt
(meaning ALL_NETWORKS), why to bother with this, just pass std::nullopt below when you call AddrMan::Size()
, unless I’m missing something here.
Next line calling AddrMan::GetAddr() function passes std::nullopt as the network argument
no, it now passes network
as the network argument, which, depending on the fuzzing seed, could be std::nullopt
or any network.
The goal of this PR is to give the fuzzer the possibility to reach network-specific code paths. If there was a bug within these, it wouldn’t be able to find it before, because they just weren’t invoked.
313+ (void)const_addr_man.Select(fuzzed_data_provider.ConsumeBool(), network);
314+ std::optional<bool> in_new;
315+ if (fuzzed_data_provider.ConsumeBool()) {
316+ in_new = fuzzed_data_provider.ConsumeBool();
317+ }
318+ (void)const_addr_man.Size(network, in_new);
As I explained my reasoning of this above in my first comment on the initialisation of the network variable:
0 (void)const_addr_man.Size(/*network=*/std::nullopt, in_new);
Tested ACK: FUZZ=addrman ./src/test/fuzz/fuzz
Tried also with a few seeds added last month by @Xekyo:
e.g.: FUZZ=addrman ./src/test/fuzz/fuzz ../qa-assets/fuzz_seed_corpus/addrman/1b02be22a08f8e28c192cb1c86f074158d18a691