Requested on IRC:
0[18:01] <vasild> => I think there is a good chance fuzzing addrman unserialize will find more bugs
1[18:04] <sipa> definitely
Requested on IRC:
0[18:01] <vasild> => I think there is a good chance fuzzing addrman unserialize will find more bugs
1[18:04] <sipa> definitely
44+ const auto ser_version{fuzzed_data_provider.ConsumeIntegral<int32_t>()};
45+ ds.SetVersion(ser_version);
46+ try {
47+ ds >> addr_man;
48+ } catch (const std::ios_base::failure&) {
49+ }
I think that addr_man
is not in a usable state if an exception is thrown (i.e. it is in an undefined state). Below we call its methods and expect they would work. Maybe:
0 try {
1 ds >> addr_man;
2 } catch (const std::ios_base::failure&) {
3 addr_man.Clear();
4 }
Concept ACK
The unserialize itself is fuzzed in:
What this test adds is calling addrman methods after it is unserialized from fuzzed data. This kind of simulates a disk corruption. I think it may result in the same addr:port being in “new” and “tried” or other “interesting” situations that do not occur from normal operation.
48+ } catch (const std::ios_base::failure&) {
49+ addr_man.Clear();
50+ }
51+ }
52 if (fuzzed_data_provider.ConsumeBool()) {
53 addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
True, this works for me.
0@@ -38,6 +38,12 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
1 SetMockTime(ConsumeTime(fuzzed_data_provider));
2 CAddrManDeterministic addr_man;
3 addr_man.MakeDeterministic(ConsumeUInt256(fuzzed_data_provider));
4+ if (fuzzed_data_provider.ConsumeBool()) {
5+ addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
6+ if (!SanityCheckASMap(addr_man.m_asmap)) {
7+ addr_man.m_asmap.clear();
8+ }
9+ }
10 if (fuzzed_data_provider.ConsumeBool()) {
11 const std::vector<uint8_t> serialized_data{ConsumeRandomLengthByteVector(fuzzed_data_provider)};
12 CDataStream ds(serialized_data, SER_DISK, INIT_PROTO_VERSION);
13@@ -49,12 +55,6 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
14 addr_man.Clear();
15 }
16 }
17- if (fuzzed_data_provider.ConsumeBool()) {
18- addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
19- if (!SanityCheckASMap(addr_man.m_asmap)) {
20- addr_man.m_asmap.clear();
21- }
22- }
git diff fa74025 aaaa9c6
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
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.