From 68e1a8c790ad7927ca2f76b764dde40b978e548c Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 11 Apr 2017 13:54:34 +0300 Subject: [PATCH] Safety check in CInstantSend::SyncTransaction (#1412) --- src/instantx.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/instantx.cpp b/src/instantx.cpp index 899ab13780..94799ff316 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -786,7 +786,17 @@ void CInstantSend::SyncTransaction(const CTransaction& tx, const CBlock* pblock) uint256 txHash = tx.GetHash(); // When tx is 0-confirmed or conflicted, pblock is NULL and nHeightNew should be set to -1 - CBlockIndex* pblockindex = pblock ? mapBlockIndex[pblock->GetHash()] : NULL; + CBlockIndex* pblockindex = NULL; + if(pblock) { + uint256 blockHash = pblock->GetHash(); + BlockMap::iterator mi = mapBlockIndex.find(blockHash); + if(mi == mapBlockIndex.end() || !mi->second) { + // shouldn't happen + LogPrint("instantsend", "CTxLockRequest::SyncTransaction -- Failed to find block %s\n", blockHash.ToString()); + return; + } + pblockindex = mi->second; + } int nHeightNew = pblockindex ? pblockindex->nHeight : -1; LogPrint("instantsend", "CInstantSend::SyncTransaction -- txid=%s nHeightNew=%d\n", txHash.ToString(), nHeightNew);