[Pkg-bitcoin-commits] [bitcoin] 78/126: Ensure backupwallet fails when attempting to backup to source file
Jonas Smedegaard
dr at jones.dk
Mon Nov 13 20:02:32 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/0.15.1_dfsg-1
in repository bitcoin.
commit fd79ed6b202ec872aa794ba6a23d4dfc373a98f1
Author: Tomas van der Wansem <tomas at tomasvdw.nl>
Date: Thu Sep 21 00:10:46 2017 +0200
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
---
src/wallet/db.cpp | 5 +++++
src/wallet/db.h | 2 +-
test/functional/walletbackup.py | 10 ++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index d2fe486..8c23d9c 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 3614e34..6f3cfe9 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 15ea26a..85a1497 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()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/bitcoin.git
More information about the Pkg-bitcoin-commits
mailing list