This patch
drops an unused
nTimeparam fromCAddrMan::Connected_()andCAddrMan::Connected()makes an
nTimeinteger truncations explicit, asCAddress::nTimeis declared in src/protocol.h as uint32 but int64 values can be written to it inCAddrMan::Connected_(). This also fixes the following non-suppressed UBSan error inaddrman.cpp:
SUMMARY: UndefinedBehaviorSanitizer
addrman.cpp:535:22: runtime error: implicit conversion
from type 'int64_t' (aka 'long') of value 68719478016 (64-bit, signed)
to type 'uint32_t' (aka 'unsigned int') changed the value to 1280 (32-bit, unsigned)
(According to https://en.cppreference.com/w/cpp/language/implicit_conversion, if the destination type is unsigned, the resulting value is the smallest unsigned value equal to the source value modulo (2 exponent n), where n is the number of bits used to represent the destination type. So it seems this is defined behavior and the signed integer is being truncated correctly. However, using a named cast makes the truncation conversion explicit and reduces the warnings by the UBSan integer sanitizer.)
does the same for two similar UBSan errors in
CAddrMan::Add_()that were suppressedfixes the following UBSan error in
CAddrMan::Unserialize()that was suppressed
SUMMARY: UndefinedBehaviorSanitizer
addrman.h:320:43: runtime error: implicit conversion
from type 'int' of value -32 (32-bit, signed)
to type 'const uint8_t' (aka 'const unsigned char')
changed the value to 224 (8-bit, unsigned)
removes the four addrman UBSan suppressions
adds TODO documentation for updates needed by the Year 2106
To test
$ ./autogen.sh && ./configure --enable-fuzz --with-sanitizers=fuzzer,address,undefined,integer CC=clang CXX=clang++ && make clean && make
$ FUZZ=addrman src/test/fuzz/fuzz ../qa-assets/fuzz_seed_corpus/addrman