-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: Add size check on meta.key_origin.path #23277
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: Add size check on meta.key_origin.path #23277
Conversation
src/wallet/scriptpubkeyman.cpp
Outdated
@@ -374,7 +374,7 @@ void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript& script) | |||
auto it = mapKeyMetadata.find(keyid); | |||
if (it != mapKeyMetadata.end()){ | |||
CKeyMetadata meta = it->second; | |||
if (!meta.hd_seed_id.IsNull() && meta.hd_seed_id != m_hd_chain.seed_id) { | |||
if (!meta.hd_seed_id.IsNull() && meta.hd_seed_id != m_hd_chain.seed_id && meta.key_origin.path.size() > 0) { |
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.
Wouldn't meta.key_origin.path.size() >= 3
be better if the worry is to go out of range here? Might also log a warning when this happens as it means (I guess?) that the wallet is somehow corrupted.
Concept ACK, I agree this shouldn't cause a crash. |
Resolves segfault on legacy wallet Log warning when meta.key_origin.path is below expected size
e3ac2c0
to
d58118f
Compare
The root cause of the problem this is fixing is that the wallet does not contain the upgraded key metadata because it is encrypted and has not been unlocked yet, and a transaction was found that involved inactive HD chains. So this segfault can be triggered with a non-corrupted wallet. I don't think it is necessarily correct to log an error and move on as doing so could result in missing funds. To avoid the crash, I think access to |
when I encountered this, this was the state of meta,
|
This matches what I expect. The meta is not upgraded (nVersion is 10, not 12, and has_key_origin is false). |
Please squash your commits. I will implement the derivation from the keypath string in a followup PR as that is a bit more complicated to deal with. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits |
Resolves #21605 segfault on legacy wallet
I also encountered same [*] when resyncing a 2017 era blockchain.