From 6b8fb971820dd28fa9f17a667baadb173da3cec7 Mon Sep 17 00:00:00 2001 From: crowning- Date: Sat, 13 Dec 2014 15:52:57 +0100 Subject: [PATCH] On client shutdown write directly into "peers.dat"... ...and not into a temporary file which gets renamed to "peers.dat" later. This prevents softlinks from being replaced by a "real" file, see http://jira.darkcoin.qa/browse/DRK-122 Update of https://github.com/darkcoin/darkcoin/pull/63 to the new Bitcoin codebase. --- src/net.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 17339f72945c..c485892f84ca 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2002,11 +2002,6 @@ CAddrDB::CAddrDB() bool CAddrDB::Write(const CAddrMan& addr) { - // Generate random temporary filename - unsigned short randv = 0; - RAND_bytes((unsigned char *)&randv, sizeof(randv)); - std::string tmpfn = strprintf("peers.dat.%04x", randv); - // serialize addresses, checksum data up to that point, then append csum CDataStream ssPeers(SER_DISK, CLIENT_VERSION); ssPeers << FLATDATA(Params().MessageStart()); @@ -2014,12 +2009,12 @@ bool CAddrDB::Write(const CAddrMan& addr) uint256 hash = Hash(ssPeers.begin(), ssPeers.end()); ssPeers << hash; - // open temp output file, and associate with CAutoFile - boost::filesystem::path pathTmp = GetDataDir() / tmpfn; - FILE *file = fopen(pathTmp.string().c_str(), "wb"); + // open output file, and associate with CAutoFile + boost::filesystem::path pathAddr = GetDataDir() / "peers.dat"; + FILE *file = fopen(pathAddr.string().c_str(), "wb"); CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION); if (!fileout) - return error("%s : Failed to open file %s", __func__, pathTmp.string()); + return error("%s : Failed to open file %s", __func__, pathAddr.string()); // Write and commit header, data try { @@ -2031,10 +2026,6 @@ bool CAddrDB::Write(const CAddrMan& addr) FileCommit(fileout); fileout.fclose(); - // replace existing peers.dat, if any, with new peers.dat.XXXX - if (!RenameOver(pathTmp, pathAddr)) - return error("%s : Rename-into-place failed", __func__); - return true; }