-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: Fix non-determinism in ParseHDKeypath(...). Avoid using an uninitialized variable in path calculation. #13712
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
wallet: Fix non-determinism in ParseHDKeypath(...). Avoid using an uninitialized variable in path calculation. #13712
Conversation
Would be nice if this was covered by a test case, no? |
7893b01
to
f239417
Compare
@MarcoFalke Thanks for the quick review. I've now added some tests. This is the subset of the added tests that failed before the fix commit and passes after the fix commit:
Please re-review :-) |
f239417
to
44a5042
Compare
src/wallet/rpcwallet.h
Outdated
@@ -31,4 +31,5 @@ bool EnsureWalletIsAvailable(CWallet *, bool avoidException); | |||
UniValue getaddressinfo(const JSONRPCRequest& request); | |||
UniValue signrawtransactionwithwallet(const JSONRPCRequest& request); | |||
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const CTransaction* txConst, int sighash_type = 1, bool sign = true, bool bip32derivs = false); | |||
bool ParseHDKeypath(std::string keypath_str, std::vector<uint32_t>& keypath); |
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.
Rather than declare it in the header, you could declare it extern
in the test file.
44a5042
to
7e788ff
Compare
7e788ff
to
27ee53c
Compare
utACK 7223263 |
utACK 7223263 |
utACK 27ee53c |
1 similar comment
utACK 27ee53c |
…id using an uninitialized variable in path calculation. 27ee53c wallet: Add error handling. Check return value of ParseUInt32(...) in ParseHDKeypath(...). (practicalswift) 7223263 wallet: Add tests for ParseHDKeypath(...) (practicalswift) Pull request description: Add error handling. Check return value of `ParseUInt32(...)` in `ParseHDKeypath(...)`. `ParseUInt32(...)` returns `false` if the entire string could not be parsed or when an overflow or underflow occurred. In such case the uninitialized variable `number` would be used in the calculation of `path` (prior to this commit). An example key path triggering this is `m/0/4294967296`: ``` ParseHDKeypath("m/0/4294967296", keypath); ``` `4294967296` is `1` + `0xFFFFFFFF` (`uint32_t` max: `4294967295`). Introduced in a4b06fb which was merged into `master` 14 hours ago as part of #13557 ("BIP 174 PSBT Serializations and RPCs"). Tree-SHA512: e5ff423f67c18d82c1231bde6343587a453e793c32004d93dc9b61be6d9372b57a6b2c9978d9eb1000d6cc82fd180f2486013f928dca737fb92daad22c16e467
@achow101 @MarcoFalke @sipa As reviewers of this bug fix you might be interested in reviewing PR #13815 which adds annotations (C++17-style |
… functions returning bool 9cc0230 Add NODISCARD to all {Decode,Parse}[...](...) functions returning bool. Sort includes. (practicalswift) 579497e tests: Explicitly ignore the return value of DecodeBase58(...) (practicalswift) 145fe95 tests: Check return value of ParseParameters(...) (practicalswift) 7c5bc2a miner: Default to DEFAULT_BLOCK_MIN_TX_FEE if unable to parse -blockmintxfee (practicalswift) Pull request description: Changes in this PR: * ~~Add linter to make sure the return value of `Parse[...](...)` is checked~~ * Add `__attribute__((warn_unused_result))` to all `{Decode,Parse}[...](...)` functions returning `bool` * Fix violations Context: * #13712: `wallet: Fix non-determinism in ParseHDKeypath(...). Avoid using an uninitialized variable in path calculation.` would have been prevented by this Tree-SHA512: 41a97899f2d5a26584235fa02b1ebfb4faacd81ea97e927022955a658fa7e15d07a1443b4b7635151a43259a1adf8f2f4de3c1c75d7b5f09f0d5496463a1dae6
Add error handling. Check return value of
ParseUInt32(...)
inParseHDKeypath(...)
.ParseUInt32(...)
returnsfalse
if the entire string could not be parsed or when an overflow or underflow occurred. In such case the uninitialized variablenumber
would be used in the calculation ofpath
(prior to this commit).An example key path triggering this is
m/0/4294967296
:4294967296
is1
+0xFFFFFFFF
(uint32_t
max:4294967295
).Introduced in a4b06fb which was merged into
master
14 hours ago as part of #13557 ("BIP 174 PSBT Serializations and RPCs").