From 308dd2e93e92f4cac4e7d75478316af9bb2b77b8 Mon Sep 17 00:00:00 2001 From: Adam Jonas Date: Mon, 21 Oct 2019 13:17:22 -0400 Subject: [PATCH] Sanity assert GetAncestor() != nullptr where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add sanity asserts for return value of `CBlockIndex::GetAncestor()` where appropriate. In validation.cpp `CheckSequenceLocks`, check the return value of `tip->GetAncestor(maxInputHeight)` stored into `lp->maxInputBlock`. If it ever returns `nullptr` because the ancestor isn't found, it's going to be a bad bug to keep going, since a `LockPoints` object with the `maxInputBlock` member set to `nullptr` signifies no relative lock time. In the other places, the added asserts would prevent accidental dereferencing of a null pointer which is undefined behavior. Co-Authored-By: Aurèle Oulès Co-Authored-By: danra --- src/consensus/tx_verify.cpp | 3 ++- src/rpc/blockchain.cpp | 23 +++++++++++------------ src/test/miner_tests.cpp | 22 +++++++++++++--------- src/validation.cpp | 14 ++++++++++---- src/versionbits.cpp | 5 +++-- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp index 5738c333ce1ee..154146f08d308 100644 --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -11,6 +11,7 @@ #include #include #include