mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-08 22:57:56 +02:00
Merge bitcoin/bitcoin#34521: validation: fix UB in LoadChainTip
20ae9b98eaExtend functional test for setBlockIndexCandidates UB (marcofleon)854a6d5a9avalidation: fix UB in LoadChainTip (marcofleon)9249e6089evalidation: remove LoadChainTip call from ActivateSnapshot (marcofleon) Pull request description: Addresses https://github.com/bitcoin/bitcoin/issues/34503. See this issue for more details as well. Fixes a bug where, under certain conditions, `setBlockIndexCandidates` had blocks in it that were worse than the tip. The block index candidate set uses `nSequenceId` as a sort key, so modifying this field while blocks are in the set results in undefined behavior. This PR populates `setBlockIndexCandidates` after the `nSequenceId` modifications, avoiding the UB. ACKs for top commit: achow101: ACK20ae9b98easedited: Re-ACK20ae9b98easipa: Code review ACK20ae9b98eaTree-SHA512: 121c170bb70fb6365089d578db63c811e7926e129d7206e569947f7a1f6c5ddc8d5f4937b80f1ba1b7d7daa42789b143ca5b56f154b7ab968a1cd55f925f378d
This commit is contained in:
@@ -77,8 +77,13 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager, TestChain100Setup)
|
||||
LOCK(::cs_main);
|
||||
c2.InitCoinsCache(1 << 23);
|
||||
c2.CoinsTip().SetBestBlock(active_tip->GetBlockHash());
|
||||
c2.setBlockIndexCandidates.insert(manager.m_blockman.LookupBlockIndex(active_tip->GetBlockHash()));
|
||||
for (const auto& cs : manager.m_chainstates) {
|
||||
cs->ClearBlockIndexCandidates();
|
||||
}
|
||||
c2.LoadChainTip();
|
||||
for (const auto& cs : manager.m_chainstates) {
|
||||
cs->PopulateBlockIndexCandidates();
|
||||
}
|
||||
}
|
||||
BlockValidationState _;
|
||||
BOOST_CHECK(c2.ActivateBestChain(_, nullptr));
|
||||
@@ -493,6 +498,9 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
|
||||
BOOST_CHECK(cs->setBlockIndexCandidates.empty());
|
||||
}
|
||||
chainman.LoadBlockIndex();
|
||||
for (const auto& cs : chainman.m_chainstates) {
|
||||
cs->PopulateBlockIndexCandidates();
|
||||
}
|
||||
};
|
||||
|
||||
// Ensure that without any assumed-valid BlockIndex entries, only the current tip is
|
||||
|
||||
Reference in New Issue
Block a user