From e3c1bafdc4579cce07ecfc6d138b4c48b87e5bb7 Mon Sep 17 00:00:00 2001 From: Lola Dam Date: Thu, 4 Jan 2018 23:07:08 +0100 Subject: [PATCH] Verify when doing 'backupwallet' that destination is not the same path of the original wallet.dat file. (#1406) --- src/wallet/wallet.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8260b2fd6..648caebc7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -463,21 +463,21 @@ bool CWallet::Verify() } catch (const boost::filesystem::filesystem_error&) { // failure is ok (well, not really, but it's not worse than what we started with) } - + // try again if (!bitdb.Open(GetDataDir())) { // if it still fails, it probably means we can't even create the database env return InitError(strprintf(_("Error initializing wallet database environment %s!"), GetDataDir())); } } - + if (GetBoolArg("-salvagewallet", false)) { // Recover readable keypairs: if (!CWalletDB::Recover(bitdb, walletFile, true)) return false; } - + if (boost::filesystem::exists(GetDataDir() / walletFile)) { CDBEnv::VerifyResult r = bitdb.Verify(walletFile, CWalletDB::Recover); @@ -492,7 +492,7 @@ bool CWallet::Verify() if (r == CDBEnv::RECOVER_FAIL) return InitError(strprintf(_("%s corrupt, salvage failed"), walletFile)); } - + return true; } @@ -2972,7 +2972,7 @@ bool CWallet::SetDefaultKey(const CPubKey &vchPubKey) /** * Mark old keypool keys as used, - * and generate all new keys + * and generate all new keys */ bool CWallet::NewKeyPool() { @@ -3897,6 +3897,11 @@ bool CWallet::BackupWallet(const std::string& strDest) pathDest /= strWalletFile; 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, boost::filesystem::copy_option::overwrite_if_exists); #else