aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas van der Wansem <tomas@tomasvdw.nl>2017-09-21 00:10:46 +0200
committerMarcoFalke <falke.marco@gmail.com>2017-11-01 15:23:06 -0400
commitfd79ed6b202ec872aa794ba6a23d4dfc373a98f1 (patch)
tree9a8e2ce5deba2c1ba8dd4c0da0145275624d80cc
parentd94fc336c47b5fd0f42217806faad1aa201b9d63 (diff)
downloadbitcoin-fd79ed6b202ec872aa794ba6a23d4dfc373a98f1.tar.xz
Ensure backupwallet fails when attempting to backup to source file
Previous behaviour was to destroy the wallet (to zero-length) Github-Pull: #11376 Rebased-From: 5d465e396249a0e2cc60b16984a2bdbe4c8993c3
-rw-r--r--src/wallet/db.cpp5
-rw-r--r--src/wallet/db.h2
-rwxr-xr-xtest/functional/walletbackup.py10
3 files changed, 16 insertions, 1 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index d2fe4866fa..8c23d9c072 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -673,6 +673,11 @@ bool CWalletDBWrapper::Backup(const std::string& strDest)
pathDest /= strFile;
try {
+ if (fs::equivalent(pathSrc, pathDest)) {
+ LogPrintf("cannot backup to wallet source file %s\n", pathDest.string());
+ return false;
+ }
+
fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists);
LogPrintf("copied %s to %s\n", strFile, pathDest.string());
return true;
diff --git a/src/wallet/db.h b/src/wallet/db.h
index 3614e34fbb..6f3cfe9557 100644
--- a/src/wallet/db.h
+++ b/src/wallet/db.h
@@ -45,7 +45,7 @@ public:
void Reset();
void MakeMock();
- bool IsMock() { return fMockDb; }
+ bool IsMock() const { return fMockDb; }
/**
* Verify that database file strFile is OK. If it is not,
diff --git a/test/functional/walletbackup.py b/test/functional/walletbackup.py
index 15ea26afa1..85a149793e 100755
--- a/test/functional/walletbackup.py
+++ b/test/functional/walletbackup.py
@@ -190,6 +190,16 @@ class WalletBackupTest(BitcoinTestFramework):
assert_equal(self.nodes[1].getbalance(), balance1)
assert_equal(self.nodes[2].getbalance(), balance2)
+ # Backup to source wallet file must fail
+ sourcePaths = [
+ tmpdir + "/node0/regtest/wallet.dat",
+ tmpdir + "/node0/./regtest/wallet.dat",
+ tmpdir + "/node0/regtest/",
+ tmpdir + "/node0/regtest"]
+
+ for sourcePath in sourcePaths:
+ assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath)
+
if __name__ == '__main__':
WalletBackupTest().main()