Skip to content

Commit 72b62ed

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#23834: wallettool: Check that the dumpfile checksum is the correct size
ac617cc wallettool: Check that the dumpfile checksum is the correct size (Andrew Chow) Pull request description: After parsing the checksum, make sure that it is the size that we expect it to be. This issue was reported by Pedro Baptista. ACKs for top commit: laanwj: Code review ACK ac617cc Tree-SHA512: 8135b3fb1f4f6b6c91cfbac7d1d3421f1f6c664a742c92940f68eae857f92ce49d042cc3aa5c2df6ef182825271483d65efc7543ec7a8ff047fd7c08666c8899
1 parent ee9b3cd commit 72b62ed

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/wallet/dump.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ bool CreateFromDump(const std::string& name, const fs::path& wallet_path, biling
215215

216216
if (key == "checksum") {
217217
std::vector<unsigned char> parsed_checksum = ParseHex(value);
218+
if (parsed_checksum.size() != checksum.size()) {
219+
error = Untranslated("Error: Checksum is not the correct size");
220+
ret = false;
221+
break;
222+
}
218223
std::copy(parsed_checksum.begin(), parsed_checksum.end(), checksum.begin());
219224
break;
220225
}

test/functional/tool_wallet.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,11 @@ def test_dump_createfromdump(self):
396396
bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum3.dump")
397397
dump_data["checksum"] = "2" * 10
398398
self.write_dump(dump_data, bad_sum_wallet_dump)
399-
self.assert_raises_tool_error('Error: Dumpfile checksum does not match. Computed {}, expected {}{}'.format(checksum, "2" * 10, "0" * 54), '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
399+
self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
400+
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload"))
401+
dump_data["checksum"] = "3" * 66
402+
self.write_dump(dump_data, bad_sum_wallet_dump)
403+
self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
400404
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload"))
401405

402406

0 commit comments

Comments
 (0)