Requested on IRC:
[18:01] <vasild> => I think there is a good chance fuzzing addrman unserialize will find more bugs
[18:04] <sipa> definitely
Requested on IRC:
[18:01] <vasild> => I think there is a good chance fuzzing addrman unserialize will find more bugs
[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:
try {
ds >> addr_man;
} catch (const std::ios_base::failure&) {
addr_man.Clear();
}
Good catch. Fixed.
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.
ACK fa740252d2dcc272204b745906785fe26e9a0b77
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);
I guess asmap should be set first, since it is used in deserialize?
True, this works for me.
@@ -38,6 +38,12 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
SetMockTime(ConsumeTime(fuzzed_data_provider));
CAddrManDeterministic addr_man;
addr_man.MakeDeterministic(ConsumeUInt256(fuzzed_data_provider));
+ if (fuzzed_data_provider.ConsumeBool()) {
+ addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
+ if (!SanityCheckASMap(addr_man.m_asmap)) {
+ addr_man.m_asmap.clear();
+ }
+ }
if (fuzzed_data_provider.ConsumeBool()) {
const std::vector<uint8_t> serialized_data{ConsumeRandomLengthByteVector(fuzzed_data_provider)};
CDataStream ds(serialized_data, SER_DISK, INIT_PROTO_VERSION);
@@ -49,12 +55,6 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
addr_man.Clear();
}
}
- if (fuzzed_data_provider.ConsumeBool()) {
- addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
- if (!SanityCheckASMap(addr_man.m_asmap)) {
- addr_man.m_asmap.clear();
- }
- }
yes
Done
Tested ACK fa740252d2dcc272204b745906785fe26e9a0b77
ACK aaaa9c6019790a1a21a7b4ef01693ac9390ae6d0 per git diff fa74025 aaaa9c6
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
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.
@vasild I am seeing there is a conflict. Do you have a preference which one should be merged first?
Ok, merging the one with the nicer commit-hash first :sweat_smile: