Skip to content

Commit

Permalink
Add memory_cleanse in two more areas where clearing is critical
Browse files Browse the repository at this point in the history
  • Loading branch information
barton2526 committed Jul 14, 2021
1 parent 18d9791 commit 698f216
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class CBase58Data
{
// zero the memory, as it may contain sensitive data
if (!vchData.empty())
memset(&vchData[0], 0, vchData.size());
memory_cleanse(&vchData[0], vchData.size());
}

void SetData(int nVersionIn, const void* pdata, size_t nSize)
Expand Down Expand Up @@ -222,7 +222,7 @@ class CBase58Data
vchData.resize(vchTemp.size() - 1);
if (!vchData.empty())
memcpy(&vchData[0], &vchTemp[1], vchData.size());
memset(&vchTemp[0], 0, vchTemp.size());
memory_cleanse(&vchTemp[0], vchTemp.size());
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void RandAddSeed()
// Seed with CPU performance counter
int64_t nCounter = GetPerformanceCounter();
RAND_add(&nCounter, sizeof(nCounter), 1.5);
memset(&nCounter, 0, sizeof(nCounter));
memory_cleanse(&nCounter, sizeof(nCounter));
}

void RandAddSeedPerfmon()
Expand All @@ -128,14 +128,14 @@ void RandAddSeedPerfmon()
// Don't need this on Linux, OpenSSL automatically uses /dev/urandom
// Seed with the entire set of perfmon data
unsigned char pdata[250000];
memset(pdata, 0, sizeof(pdata));
memory_cleanse(pdata, sizeof(pdata));
unsigned long nSize = sizeof(pdata);
long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", nullptr, nullptr, pdata, &nSize);
RegCloseKey(HKEY_PERFORMANCE_DATA);
if (ret == ERROR_SUCCESS)
{
RAND_add(pdata, nSize, nSize/100.0);
memset(pdata, 0, nSize);
memory_cleanse(pdata, nSize);
LogPrint(BCLog::LogFlags::NOISY, "rand", "RandAddSeed() %lu bytes", nSize);
}
#endif
Expand Down

0 comments on commit 698f216

Please sign in to comment.