Repository navigation
Conversation
AvailableCoins() takes an optional CCoinControl pointer that defaults to nullptr, and the other uses of it check for null first. The TRUC version filter added in ec2676b does not, so a call without coin control dereferences a null pointer as soon as the wallet has an unconfirmed output in the mempool. No current caller hits this: RPCs, the GUI and CreateTransaction always pass a coin control, and the tests and benchmarks that use the default only have confirmed coins. Treat a missing coin control like one that does not request a TRUC transaction, and add a test that calls AvailableCoins() with the default argument on a wallet with an unconfirmed transaction.
Add wallet transactions in the mempool state with a fuzzed version, and call AvailableCoins() directly with an optional null coin control, an optional fuzzed feerate and fuzzed filter params, including min_sum_amount and max_count to reach the early-return paths.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsNo conflicts as of last run. |
|
Concept ACK |
|
tACK 032be32 Left one non-blocking nit inline |
|
|
||
| BOOST_FIXTURE_TEST_CASE(available_unconfirmed_coins_without_coin_control, TestChain100Setup) | ||
| { | ||
| CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); |
There was a problem hiding this comment.
nit: The CreateAndProcessBlock line might be unnecessary, the block's coinbase is already spendable and mature at height 100, and without this line, the test still crashes and passes too. Was this on purpose?
| BOOST_REQUIRE(wallet->AddToWallet(MakeTransactionRef(CreateValidMempoolTransaction(m_coinbase_txns[0], /*input_vout=*/0, /*input_height=*/0, coinbaseKey, wallet_script)), TxStateInMempool{})); | ||
|
|
||
| LOCK(wallet->cs_wallet); | ||
| BOOST_CHECK_NO_THROW(AvailableCoins(*wallet)); |
There was a problem hiding this comment.
nit: Without the BOOST_CHECK_NO_THROW wrap, the test still crashes without the fix and passes with it. I think that's because null dereference isn't an exception, so it wouldn't be caught. You could consider checking the results of AvailableCoins instead, like the size.
(I checked the size was 1 locally)
| BOOST_CHECK_NO_THROW(AvailableCoins(*wallet)); | |
| BOOST_CHECK_EQUAL(AvailableCoins(*wallet).Size(), 1U); |
|
tACK 032be32 tested both the unit test and the fuzz test individually, they crashed without the fix and passed with it. I left two non-blocking inline comments. Also, I replayed the existing qa-assets corpus and noticed less coverage on this PR compared to master (cov 19380 → 18366, ft 109275 → 67187 on my machine). Since the new |

AvailableCoins() takes an optional CCoinControl pointer that defaults to nullptr, and the other uses of it check for null first. The TRUC version filter added in ec2676b does not, so a call without coin control dereferences a null pointer as soon as the wallet has an unconfirmed output in the mempool.
Found this issue with few seconds of fuzzing with the change in the second commit which adds wallet transactions in the mempool state with a fuzzed version, and call
AvailableCoins()directly with an optional null coin control.