-
Notifications
You must be signed in to change notification settings - Fork 37.7k
rpc: fix getrawtransaction segfault #29003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The crash would happen when querying a mempool transaction with verbosity=2, while pruning.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
lgtm ACK 494a926 A test wouldn't hurt, I'd say. |
I guess this was introduced in f866971 |
@@ -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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated: I don't understand the silent fallback to verbose=1, when verbose=2 is not available. Either this should be documented, or an error should be thrown (same below).
Though, this is unrelated.
I think we should avoid the use of pointers when they are assumed to not be null. In C++, references exit. However, this can be done in a follow-up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK 494a926
I've managed to reproduce the issue, this PR fixes it.
Will add one soon. |
Sorry, why not fixing the issue directly here(?): --- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -585,7 +585,7 @@ const CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
{
AssertLockHeld(::cs_main);
- return (m_have_pruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
+ return (m_have_pruned && (pblockindex != nullptr) && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
} Or even |
I initially decided against this because
I think that it's not one or the other, both changes make sense. However, to avoid the question if |
Perhaps a test for this case? Edit: Oh, one has already been requested. |
Concept ACK |
I added a regression test (that will segfault on master). In order to trigger this, it's not enough to enable pruning, you have to actually have pruned a block, so I did this with |
This fails on master without the previous commit.
4a259fd
to
9075a44
Compare
Concept ACK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK 9075a44
Reproduced the crash on master with my pruned node manually via
$ ./src/bitcoin-cli getrawmempool | head -n 2
[
"sometxid...",
$ ./src/bitcoin-cli getrawtransaction sometxid... 2
error: timeout on transient error: Could not connect to the server 127.0.0.1:8332 (error code 1 - "EOF reached")
Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
-----
bitcoind crashes with "Segmentation fault (core dumped)"
and verified that the PR fixes it. Also checked that the test crashes if cherry-picked on master, and succeeds in the PR branch.
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: bitcoin#29003 Rebased-From: 494a926
This fails on master without the previous commit. Github-Pull: bitcoin#29003 Rebased-From: 9075a44
Added to #29011 for backporting to 26.x. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: bitcoin#29003 Rebased-From: 494a926
This fails on master without the previous commit. Github-Pull: bitcoin#29003 Rebased-From: 9075a44
Added to #28768 for backporting to 25.x. |
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: bitcoin#29003 Rebased-From: 494a926
This fails on master without the previous commit. Github-Pull: bitcoin#29003 Rebased-From: 9075a44
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: bitcoin#29003 Rebased-From: 494a926
This fails on master without the previous commit. Github-Pull: bitcoin#29003 Rebased-From: 9075a44
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: bitcoin#29003 Rebased-From: 494a926
This fails on master without the previous commit. Github-Pull: bitcoin#29003 Rebased-From: 9075a44
… pointer fa5989d refactor: rpc: Pass CBlockIndex by reference instead of pointer (MarcoFalke) fa604eb refactor: Use reference instead of pointer in IsBlockPruned (MarcoFalke) Pull request description: Follow-up to #29003 (comment) ACKs for top commit: TheCharlatan: ACK fa5989d pablomartin4btc: tACK fa5989d dergoegge: Code review ACK fa5989d Tree-SHA512: 7449de3e3bb435dcbf438df88df343bb70f6edc3228ee7c0078f912ffb415e951ba30f8ecad916765f8cf896f0d784fe30535c5cf997e303cf5af257ade69773
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: bitcoin#29003 Rebased-From: 494a926
This fails on master without the previous commit. Github-Pull: bitcoin#29003 Rebased-From: 9075a44
7b79e54 doc: update release notes for 26.x (fanquake) ccf00b1 wallet: Fix use-after-free in WalletBatch::EraseRecords (MarcoFalke) 40252e1 ci: Set `HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` to avoid failures (Hennadii Stepanov) b06b14e rpc: getwalletinfo, return wallet 'birthtime' (furszy) 1283401 test: coverage for wallet birth time interaction with -reindex (furszy) 0fa47e2 wallet: fix legacy spkm default birth time (furszy) 84f4a6c wallet: birth time update during tx scanning (furszy) 074296d refactor: rename FirstKeyTimeChanged to MaybeUpdateBirthTime (furszy) 35039ac fuzz: disable BnB when SFFO is enabled (furszy) 903b462 test: add coverage for BnB-SFFO restriction (furszy) 05d0576 wallet: create tx, log resulting coin selection info (furszy) 5493ebb wallet: skip BnB when SFFO is active (Murch) b15e2e2 test: add regression test for the getrawtransaction segfault (Martin Zumsande) 5097bb3 rpc: fix getrawtransaction segfault (Martin Zumsande) 81e744a ci: Use Ubuntu 24.04 Noble for asan (MarcoFalke) 69e53d1 ci: Use Ubuntu 24.04 Noble for tsan,tidy,fuzz (MarcoFalke) d2c80b6 doc: Missing additions to 26.0 release notes (fanquake) 8dc2c75 doc: add historical release notes for 26.0 (fanquake) Pull request description: Backports for `26.x`. Currently: * #28920 * #28992 * #28994 * #29003 * #29023 * #29080 * #29176 ACKs for top commit: TheCharlatan: ACK 7b79e54 glozow: ACK 7b79e54, matches mine Tree-SHA512: 898aec76ed3ad35e0edd0980af5bcc21bd60003bbf69e0b4f473ed2aa38c4e3b360b930bc3747cf798195906a8f9fe66417524f5e5ef40fa68f1c1aaceebdeb0
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: bitcoin#29003 Rebased-From: 494a926
This fails on master without the previous commit. Github-Pull: bitcoin#29003 Rebased-From: 9075a44
53bbda5 doc: update release notes for 25.x (fanquake) 31e1e03 test: add regression test for the getrawtransaction segfault (Martin Zumsande) 041228d rpc: fix getrawtransaction segfault (Martin Zumsande) b86285d gui: fix crash on selecting "Mask values" in transaction view (Sebastian Falbesoner) c21024f doc: add historical release notes for 25.1 (fanquake) Pull request description: Collecting backports for the 25.x branch. Currently: * bitcoin-core/gui#774 * #29003 ACKs for top commit: stickies-v: ACK 53bbda5 Tree-SHA512: 9b1ba17cce9de70d20329372ba71225dd930718a1f7db84a7be764dcfbba01c5e466255e7b95433ab6d7559ee8aaa04cc99ee5d1512d91fcc0a8015f1aa4150a
The crash, reported in #28986, happens when calling
getrawtransaction
for any mempool transaction withverbosity=2
, while pruning, because the rpc callsIsBlockPruned(const CBlockIndex* pblockindex)
, which dereferencespblockindex
without a check.For ease of backporting this PR fixes it just locally in
rpc/rawtransaction.cpp
by moving the check for!blockindex
up so thatIsBlockPruned()
will not be called with anullptr
. We might also want to changeIsBlockPruned()
so it doesn't crash when called with anullptr
, but I didn't do that here.Fixes #28986