-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Sanity assert GetAncestor() != nullptr where appropriate #11342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There are other places where the result of |
@@ -316,6 +316,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool | |||
} | |||
} | |||
lp->maxInputBlock = tip->GetAncestor(maxInputHeight); | |||
assert(lp->maxInputBlock != nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just assert(lp->maxInputBlock);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@promag While legal, I believe for security-critical code implicit conversions such as these should be discouraged. See also http://releases.llvm.org/3.8.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability-implicit-bool-cast.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why implicit conversions should be discouraged for floating point numbers and integers or bools, but I don't see any danger or downsides of assert(some_pointer);
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 UB.
@promag Done, |
Any specific reason for using |
The last travis run for this pull request was 302 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened. |
Needs rebase |
Closing because of inactivity, see that @MarcoFalke already added up for grabs |
Add sanity asserts for return value of
CBlockIndex::GetAncestor()
where appropriate.In validation.cpp
CheckSequenceLocks
, check the return value oftip->GetAncestor(maxInputHeight)
stored intolp->maxInputBlock
. If it ever returnsnullptr
because the ancestor isn't found, it's going to be a bad bug to keep going, since aLockPoints
object with themaxInputBlock
member set tonullptr
signifies no relative lock time.In the other places, the added asserts would prevent accidental dereferencing of a null pointer which is UB.