aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlaanwj <126646+laanwj@users.noreply.github.com>2022-01-05 19:08:07 +0100
committerlaanwj <126646+laanwj@users.noreply.github.com>2022-01-05 19:16:28 +0100
commit801aaac2b39564aa14009785146ba26d2506fb53 (patch)
treee1df22a322c888f13bc774b14b28e58530098447
parent34118bfaddc3a6c1593345c7d2369d1004a887d1 (diff)
parentac617cc141fe05bea0dc5e8f9df3da43c0945842 (diff)
downloadbitcoin-801aaac2b39564aa14009785146ba26d2506fb53.tar.xz
Merge bitcoin/bitcoin#23834: wallettool: Check that the dumpfile checksum is the correct size
ac617cc141fe05bea0dc5e8f9df3da43c0945842 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 ac617cc141fe05bea0dc5e8f9df3da43c0945842 Tree-SHA512: 8135b3fb1f4f6b6c91cfbac7d1d3421f1f6c664a742c92940f68eae857f92ce49d042cc3aa5c2df6ef182825271483d65efc7543ec7a8ff047fd7c08666c8899
-rw-r--r--src/wallet/dump.cpp5
-rwxr-xr-xtest/functional/tool_wallet.py6
2 files changed, 10 insertions, 1 deletions
diff --git a/src/wallet/dump.cpp b/src/wallet/dump.cpp
index 645576ef91..9a4c201c4a 100644
--- a/src/wallet/dump.cpp
+++ b/src/wallet/dump.cpp
@@ -214,6 +214,11 @@ bool CreateFromDump(const std::string& name, const fs::path& wallet_path, biling
if (key == "checksum") {
std::vector<unsigned char> parsed_checksum = ParseHex(value);
+ if (parsed_checksum.size() != checksum.size()) {
+ error = Untranslated("Error: Checksum is not the correct size");
+ ret = false;
+ break;
+ }
std::copy(parsed_checksum.begin(), parsed_checksum.end(), checksum.begin());
break;
}
diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py
index afe4dba7b4..2cb9dc4523 100755
--- a/test/functional/tool_wallet.py
+++ b/test/functional/tool_wallet.py
@@ -390,7 +390,11 @@ class ToolWalletTest(BitcoinTestFramework):
bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum3.dump")
dump_data["checksum"] = "2" * 10
self.write_dump(dump_data, bad_sum_wallet_dump)
- 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')
+ self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
+ assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload"))
+ dump_data["checksum"] = "3" * 66
+ self.write_dump(dump_data, bad_sum_wallet_dump)
+ self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload"))