-
-
Notifications
You must be signed in to change notification settings - Fork 367
identifysparkcoins crash fix #1710
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
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/wallet/rpcwallet.cpp (1)
4187-4192: Similar vulnerability: unchecked GetTransaction call.The
getsparkcoinaddrfunction has the same pattern as the bug that was just fixed inidentifysparkcoins. IfGetTransactionfails and returns false,txwill be uninitialized, causing a potential crash when dereferenced.Apply this diff to add the same defensive check:
uint256 txHash; txHash.SetHex(request.params[0].get_str()); CTransactionRef tx; uint256 hashBlock; - GetTransaction(txHash, tx, Params().GetConsensus(), hashBlock); + if (!GetTransaction(txHash, tx, Params().GetConsensus(), hashBlock)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, + "Transaction not found for the given txHash");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/wallet/rpcwallet.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/wallet/rpcwallet.cpp (2)
src/validation.cpp (2)
GetTransaction(1677-1730)GetTransaction(1677-1677)src/chainparams.cpp (4)
Params(1348-1351)Params(1348-1348)Params(1353-1365)Params(1353-1353)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: build-mac-cmake
- GitHub Check: build-guix-x86_64-linux-gnu
- GitHub Check: build-mac-cmake
- GitHub Check: build-guix-x86_64-apple-darwin
- GitHub Check: build-guix-x86_64-linux-gnu
- GitHub Check: build-guix-aarch64-linux-gnu
- GitHub Check: build-guix-arm64-apple-darwin
- GitHub Check: build-guix-x86_64-w64-mingw32
- GitHub Check: build-windows-cmake
- GitHub Check: build-linux-cmake
| if (!GetTransaction(txHash, tx, Params().GetConsensus(), hashBlock)) | ||
| throw std::runtime_error( | ||
| "Transaction is not found by the given txHash."); |
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.
Use JSONRPCError for consistency with other RPC error handling.
The defensive check correctly prevents the crash, but should throw JSONRPCError instead of std::runtime_error to be consistent with error handling patterns used throughout this RPC module (see lines 2188, 4812, etc.).
Apply this diff:
if (!GetTransaction(txHash, tx, Params().GetConsensus(), hashBlock))
- throw std::runtime_error(
- "Transaction is not found by the given txHash.");
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
+ "Transaction not found for the given txHash");📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (!GetTransaction(txHash, tx, Params().GetConsensus(), hashBlock)) | |
| throw std::runtime_error( | |
| "Transaction is not found by the given txHash."); | |
| if (!GetTransaction(txHash, tx, Params().GetConsensus(), hashBlock)) | |
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |
| "Transaction not found for the given txHash"); |
🤖 Prompt for AI Agents
In src/wallet/rpcwallet.cpp around lines 4150 to 4152, replace the thrown
std::runtime_error with a JSONRPCError to match the RPC module's error handling;
throw a JSONRPCError with an appropriate RPC error code (e.g.
RPC_INVALID_ADDRESS_OR_KEY or RPC_MISC_ERROR) and the existing message
"Transaction is not found by the given txHash." so callers receive a proper RPC
error object instead of a raw exception.
aleflm
left a comment
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.
LGTM. Thank you
|
Tested confirmed working. |
fixes the issue #1704