wallet: do not allow loading descriptor with an invalid ID

If the computed descriptor's ID doesn't match the wallet's
DB spkm ID, return early from the loading process to prevent
DB data from being modified in any post-loading procedure
(e.g 'TopUp' updates the descriptor's data).
This commit is contained in:
furszy
2023-06-20 13:38:14 -03:00
parent d6ee03507f
commit 1d207e3931
2 changed files with 35 additions and 1 deletions

View File

@@ -803,6 +803,12 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
}
pwallet->LoadDescriptorScriptPubKeyMan(id, desc);
// Prior to doing anything with this spkm, verify ID compatibility
if (id != pwallet->GetDescriptorScriptPubKeyMan(desc)->GetID()) {
strErr = "The descriptor ID calculated by the wallet differs from the one in DB";
return DBErrors::CORRUPT;
}
DescriptorCache cache;
// Get key cache for this descriptor