Skip to content

Commit

Permalink
rpc: fix getrawtransaction segfault
Browse files Browse the repository at this point in the history
The crash would happen when querying a mempool transaction with verbosity=2, while pruning.
  • Loading branch information
mzumsande committed Dec 5, 2023
1 parent 6d57909 commit 494a926
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static RPCHelpMan getrawtransaction()
LOCK(cs_main);
blockindex = chainman.m_blockman.LookupBlockIndex(hash_block);
}
if (verbosity == 1) {
if (verbosity == 1 || !blockindex) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;
}
Expand All @@ -405,8 +405,7 @@ static RPCHelpMan getrawtransaction()
CBlock block;
const bool is_block_pruned{WITH_LOCK(cs_main, return chainman.m_blockman.IsBlockPruned(blockindex))};

if (tx->IsCoinBase() ||
!blockindex || is_block_pruned ||
if (tx->IsCoinBase() || is_block_pruned ||
!(chainman.m_blockman.UndoReadFromDisk(blockUndo, *blockindex) && chainman.m_blockman.ReadBlockFromDisk(block, *blockindex))) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;
Expand Down

0 comments on commit 494a926

Please sign in to comment.