Skip to content

Commit fa097d0

Browse files
author
MarcoFalke
committed
addrman: Log too low compat value
Also remove uint8_t{} casts from values that are already of the same type.
1 parent ee8c997 commit fa097d0

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/addrman.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,18 @@ void AddrManImpl::Unserialize(Stream& s_)
246246

247247
uint8_t compat;
248248
s >> compat;
249+
if (compat < INCOMPATIBILITY_BASE) {
250+
throw std::ios_base::failure(strprintf(
251+
"Corrupted addrman database: The compat value (%u) "
252+
"is lower than the expected minimum value %u.",
253+
compat, INCOMPATIBILITY_BASE));
254+
}
249255
const uint8_t lowest_compatible = compat - INCOMPATIBILITY_BASE;
250256
if (lowest_compatible > FILE_FORMAT) {
251257
throw InvalidAddrManVersionError(strprintf(
252258
"Unsupported format of addrman database: %u. It is compatible with formats >=%u, "
253259
"but the maximum supported by this version of %s is %u.",
254-
uint8_t{format}, uint8_t{lowest_compatible}, PACKAGE_NAME, uint8_t{FILE_FORMAT}));
260+
uint8_t{format}, lowest_compatible, PACKAGE_NAME, uint8_t{FILE_FORMAT}));
255261
}
256262

257263
s >> nKey;

test/functional/feature_addrman.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ def run_test(self):
6868
self.start_node(0, extra_args=["-checkaddrman=1"])
6969
assert_equal(self.nodes[0].getnodeaddresses(), [])
7070

71+
self.log.info("Check that addrman with negative lowest_compatible cannot be read")
72+
self.stop_node(0)
73+
write_addrman(peers_dat, lowest_compatible=-32)
74+
self.nodes[0].assert_start_raises_init_error(
75+
expected_msg=init_error(
76+
"Corrupted addrman database: The compat value \\(0\\) is lower "
77+
"than the expected minimum value 32.: (.+)"
78+
),
79+
match=ErrorMatch.FULL_REGEX,
80+
)
81+
7182
self.log.info("Check that addrman from future is overwritten with new addrman")
7283
self.stop_node(0)
7384
write_addrman(peers_dat, lowest_compatible=111)

test/sanitizer_suppressions/ubsan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ implicit-integer-sign-change:script/bitcoinconsensus.cpp
6262
implicit-integer-sign-change:script/interpreter.cpp
6363
implicit-integer-sign-change:serialize.h
6464
implicit-integer-sign-change:txmempool.cpp
65-
implicit-signed-integer-truncation:addrman.cpp
6665
implicit-signed-integer-truncation:crypto/
6766
implicit-unsigned-integer-truncation:crypto/
6867
shift-base:arith_uint256.cpp

0 commit comments

Comments
 (0)