Fix a null pointer dereference that occurs when formatting an error message, if we haven't activated an upgrade as expected.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
2d77cd241a
commit
a76e568800
50
src/main.cpp
50
src/main.cpp
|
@ -1838,20 +1838,44 @@ bool IsInitialBlockDownload(const CChainParams& chainParams)
|
||||||
// we are not on the correct chain. As we have already checked that the current
|
// we are not on the correct chain. As we have already checked that the current
|
||||||
// chain satisfies the minimum chain work, this is likely an adversarial situation
|
// chain satisfies the minimum chain work, this is likely an adversarial situation
|
||||||
// where the node is being fed a fake alternate chain; shut down for safety.
|
// where the node is being fed a fake alternate chain; shut down for safety.
|
||||||
|
//
|
||||||
|
// Note that this depends on the assumption that if we set hashActivationBlock for
|
||||||
|
// any upgrade, we also update nMinimumChainWork to be past that upgrade.
|
||||||
|
//
|
||||||
auto upgrade = chainParams.GetConsensus().vUpgrades[idx];
|
auto upgrade = chainParams.GetConsensus().vUpgrades[idx];
|
||||||
if (upgrade.hashActivationBlock && (
|
if (upgrade.hashActivationBlock) {
|
||||||
!chainParams.GetConsensus().NetworkUpgradeActive(chainActive.Height(), Consensus::UpgradeIndex(idx))
|
if (!chainParams.GetConsensus().NetworkUpgradeActive(chainActive.Height(), Consensus::UpgradeIndex(idx))) {
|
||||||
|| chainActive[upgrade.nActivationHeight]->GetBlockHash() != upgrade.hashActivationBlock.get()
|
AbortNode(
|
||||||
)) {
|
strprintf(
|
||||||
AbortNode(
|
"%s: We are on a chain with sufficient work, but the %s network upgrade has not activated as expected.\n"
|
||||||
strprintf(
|
"Likely adversarial condition; shutting down for safety.\n"
|
||||||
"%s: Activation block hash mismatch for the %s network upgrade (expected %s, found %s). Likely adversarial condition; shutting down for safety.",
|
" nChainWork=%s\n nMinimumChainWork=%s\n tip height=%d\n upgrade height=%d",
|
||||||
__func__,
|
__func__,
|
||||||
NetworkUpgradeInfo[idx].strName,
|
NetworkUpgradeInfo[idx].strName,
|
||||||
upgrade.hashActivationBlock.get().GetHex(),
|
chainActive.Tip()->nChainWork.GetHex(),
|
||||||
chainActive[upgrade.nActivationHeight]->GetBlockHash().GetHex()),
|
chainParams.GetConsensus().nMinimumChainWork.GetHex(),
|
||||||
_("We are on a chain with sufficient work, but the network upgrade checkpoints do not match. Your node may be under attack! Shutting down for safety."));
|
chainActive.Height(),
|
||||||
return true;
|
upgrade.nActivationHeight),
|
||||||
|
_("We are on a chain with sufficient work, but an expected network upgrade has not activated. Your node may be under attack! Shutting down for safety."));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (chainActive[upgrade.nActivationHeight]->GetBlockHash() != upgrade.hashActivationBlock.get()) {
|
||||||
|
AbortNode(
|
||||||
|
strprintf(
|
||||||
|
"%s: We are on a chain with sufficient work, but the activation block hash for the %s network upgrade is not as expected.\n"
|
||||||
|
"Likely adversarial condition; shutting down for safety.\n",
|
||||||
|
" nChainWork=%s\n nMinimumChainWork=%s\n tip height=%d\n upgrade height=%d\n expected hash=%s\n actual hash=%s",
|
||||||
|
__func__,
|
||||||
|
NetworkUpgradeInfo[idx].strName,
|
||||||
|
chainActive.Tip()->nChainWork.GetHex(),
|
||||||
|
chainParams.GetConsensus().nMinimumChainWork.GetHex(),
|
||||||
|
chainActive.Height(),
|
||||||
|
upgrade.nActivationHeight,
|
||||||
|
upgrade.hashActivationBlock.get().GetHex(),
|
||||||
|
chainActive[upgrade.nActivationHeight]->GetBlockHash().GetHex()),
|
||||||
|
_("We are on a chain with sufficient work, but the network upgrade checkpoints do not match. Your node may be under attack! Shutting down for safety."));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
|
if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
|
||||||
|
|
Loading…
Reference in New Issue