Skip to content

Commit 1b8c884

Browse files
author
MarcoFalke
committed
Merge #11376: Ensure backupwallet fails when attempting to backup to source file
5d465e3 Ensure backupwallet fails when attempting to backup to source file (Tomas van der Wansem) Pull request description: Previous behaviour was to destroy the wallet (to zero-length) This fixes #11375 Tree-SHA512: bfd1738659b15e3f23b6bbdf55ec12269c62c820bf701daec19500b52bd5845bb5516733c6f76f36197eb155182a8a35dc239ad4de2ef1e59bbb0f124a455759
2 parents cffa5ee + 5d465e3 commit 1b8c884

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/wallet/db.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,11 @@ bool CWalletDBWrapper::Backup(const std::string& strDest)
705705
pathDest /= strFile;
706706

707707
try {
708+
if (fs::equivalent(pathSrc, pathDest)) {
709+
LogPrintf("cannot backup to wallet source file %s\n", pathDest.string());
710+
return false;
711+
}
712+
708713
fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists);
709714
LogPrintf("copied %s to %s\n", strFile, pathDest.string());
710715
return true;

test/functional/walletbackup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ def run_test(self):
190190
assert_equal(self.nodes[1].getbalance(), balance1)
191191
assert_equal(self.nodes[2].getbalance(), balance2)
192192

193+
# Backup to source wallet file must fail
194+
sourcePaths = [
195+
tmpdir + "/node0/regtest/wallet.dat",
196+
tmpdir + "/node0/./regtest/wallet.dat",
197+
tmpdir + "/node0/regtest/",
198+
tmpdir + "/node0/regtest"]
199+
200+
for sourcePath in sourcePaths:
201+
assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath)
202+
193203

194204
if __name__ == '__main__':
195205
WalletBackupTest().main()

0 commit comments

Comments
 (0)