Skip to content

Commit 801aaac

Browse files
committed
Merge bitcoin/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
2 parents 34118bf + ac617cc commit 801aaac

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
@@ -214,6 +214,11 @@ bool CreateFromDump(const std::string& name, const fs::path& wallet_path, biling
214214

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

test/functional/tool_wallet.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ def test_dump_createfromdump(self):
390390
bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum3.dump")
391391
dump_data["checksum"] = "2" * 10
392392
self.write_dump(dump_data, bad_sum_wallet_dump)
393-
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')
393+
self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
394+
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload"))
395+
dump_data["checksum"] = "3" * 66
396+
self.write_dump(dump_data, bad_sum_wallet_dump)
397+
self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
394398
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload"))
395399

396400

0 commit comments

Comments
 (0)