fuzz: Avoid initializing version to less than MIN_PEER_PROTO_VERSION #20995
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a fuzz bug introduced in #20881. Previously the nodes in the fuzz tests had their version initialized to a constant (
PROTOCOL_VERSION
). After #20881, the nodes have their version initialized to an arbitrary signed integer. This is problematic for several reasons:nVersion
andm_greatest_common_version
may be initialized to0
. If aversion
message is processed, this leads to a crash, becausem_greatest_common_version
must beINIT_PROTO_VERSION
while theversion
message is processed. See net: Assume that SetCommonVersion is called at most once per peer #20138nVersion
is[MIN_PEER_PROTO_VERSION, std::numeric_limits<int32_t>::max()]
(see check in net_processing)m_greatest_common_version
isstd::min(nVersion, PROTOCOL_VERSION)
(see net_processing)Fix all issues by initializing
nVersion
andm_greatest_common_version
to their valid ranges.The crashers, if someone wants to try this at home: