diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2023-12-05 13:07:39 -0500 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2024-01-15 15:23:49 +0000 |
commit | 041228d293a24c52631e011fc002349337d0645e (patch) | |
tree | 0da3032d31bb36fc988a71987e761b4aa18b6496 | |
parent | b86285df1f949c44445165040dfb94a560c3858c (diff) |
rpc: fix getrawtransaction segfault
The crash would happen when querying a mempool transaction with verbosity=2, while pruning.
Github-Pull: #29003
Rebased-From: 494a926d05df44b60b3bc1145ad2a64acf96f61b
-rw-r--r-- | src/rpc/rawtransaction.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 21d49fda9d..4ab8a8661b 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -310,7 +310,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; } @@ -319,8 +319,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 || !(UndoReadFromDisk(blockUndo, blockindex) && ReadBlockFromDisk(block, blockindex, Params().GetConsensus()))) { TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate()); return result; |