Skip to content

Commit 5d465e3

Browse files
committed
Ensure backupwallet fails when attempting to backup to source file
Previous behaviour was to destroy the wallet (to zero-length)
1 parent 5a9da37 commit 5d465e3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/wallet/db.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,11 @@ bool CWalletDBWrapper::Backup(const std::string& strDest)
672672
pathDest /= strFile;
673673

674674
try {
675+
if (fs::equivalent(pathSrc, pathDest)) {
676+
LogPrintf("cannot backup to wallet source file %s\n", pathDest.string());
677+
return false;
678+
}
679+
675680
fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists);
676681
LogPrintf("copied %s to %s\n", strFile, pathDest.string());
677682
return true;

test/functional/walletbackup.py

+10
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)