Prior to this commit there was an implicit assumption that the CBlockIndex pindexWalk (+ pindexLast and pindexWalk->pprev) being non-NULL. (If that was guaranteed pindexWalk would not be needed in while (pindexWalk && ...) on line 2233).
pindexWalk is being used in the check ...
if (!chainActive.Contains(pindexWalk)) {
CChain.Contains(...) is defined as:
bool Contains(const CBlockIndex *pindex) const {
return (*this)[pindex->nHeight] == pindex;
}
Hence, a NULL pointer dereference in the case of a non-NULL argument to Contains(...).
This commit adds two assertion which make the mentioned assumptions explicit, and removes the possibility of a NULL pointer dereference.