Skip to content

Commit 494a926

Browse files
committed
rpc: fix getrawtransaction segfault
The crash would happen when querying a mempool transaction with verbosity=2, while pruning.
1 parent 6d57909 commit 494a926

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static RPCHelpMan getrawtransaction()
396396
LOCK(cs_main);
397397
blockindex = chainman.m_blockman.LookupBlockIndex(hash_block);
398398
}
399-
if (verbosity == 1) {
399+
if (verbosity == 1 || !blockindex) {
400400
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
401401
return result;
402402
}
@@ -405,8 +405,7 @@ static RPCHelpMan getrawtransaction()
405405
CBlock block;
406406
const bool is_block_pruned{WITH_LOCK(cs_main, return chainman.m_blockman.IsBlockPruned(blockindex))};
407407

408-
if (tx->IsCoinBase() ||
409-
!blockindex || is_block_pruned ||
408+
if (tx->IsCoinBase() || is_block_pruned ||
410409
!(chainman.m_blockman.UndoReadFromDisk(blockUndo, *blockindex) && chainman.m_blockman.ReadBlockFromDisk(block, *blockindex))) {
411410
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
412411
return result;

0 commit comments

Comments
 (0)