diff --git a/qa/rpc-tests/walletbackup.py b/qa/rpc-tests/walletbackup.py --- a/qa/rpc-tests/walletbackup.py +++ b/qa/rpc-tests/walletbackup.py @@ -199,6 +199,17 @@ 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_jsonrpc(-4, "backup failed", + self.nodes[0].backupwallet, sourcePath) + if __name__ == '__main__': WalletBackupTest().main() diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4396,6 +4396,14 @@ } try { + + if (boost::filesystem::equivalent(pathSrc, pathDest)) { + LogPrintf("cannot backup to wallet source file %s\n", + pathDest.string()); + return false; + + } + #if BOOST_VERSION >= 104000 boost::filesystem::copy_file( pathSrc, pathDest,