mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #3217
fde4489e
wipeable_string: call memwipe directly (moneromooo-monero)
This commit is contained in:
commit
0c71197892
3 changed files with 6 additions and 15 deletions
|
@ -58,13 +58,10 @@ namespace epee
|
||||||
wipeable_string &operator=(wipeable_string &&other);
|
wipeable_string &operator=(wipeable_string &&other);
|
||||||
wipeable_string &operator=(const wipeable_string &other);
|
wipeable_string &operator=(const wipeable_string &other);
|
||||||
|
|
||||||
static void set_wipe(void *(*f)(void*, size_t)) { wipefunc = f; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void grow(size_t sz, size_t reserved = 0);
|
void grow(size_t sz, size_t reserved = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<char> buffer;
|
std::vector<char> buffer;
|
||||||
static void *(*wipefunc)(void*, size_t);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,13 @@
|
||||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "memwipe.h"
|
||||||
#include "misc_log_ex.h"
|
#include "misc_log_ex.h"
|
||||||
#include "wipeable_string.h"
|
#include "wipeable_string.h"
|
||||||
|
|
||||||
namespace epee
|
namespace epee
|
||||||
{
|
{
|
||||||
|
|
||||||
void *(*wipeable_string::wipefunc)(void*, size_t) = NULL;
|
|
||||||
|
|
||||||
wipeable_string::wipeable_string(const wipeable_string &other):
|
wipeable_string::wipeable_string(const wipeable_string &other):
|
||||||
buffer(other.buffer)
|
buffer(other.buffer)
|
||||||
{
|
{
|
||||||
|
@ -55,12 +54,11 @@ wipeable_string::wipeable_string(const std::string &other)
|
||||||
|
|
||||||
wipeable_string::wipeable_string(std::string &&other)
|
wipeable_string::wipeable_string(std::string &&other)
|
||||||
{
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(wipefunc, "wipefunc is not set");
|
|
||||||
grow(other.size());
|
grow(other.size());
|
||||||
memcpy(buffer.data(), other.c_str(), size());
|
memcpy(buffer.data(), other.c_str(), size());
|
||||||
if (!other.empty())
|
if (!other.empty())
|
||||||
{
|
{
|
||||||
wipefunc(&other[0], other.size()); // we're kinda left with this again aren't we
|
memwipe(&other[0], other.size()); // we're kinda left with this again aren't we
|
||||||
other = std::string();
|
other = std::string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,30 +76,28 @@ wipeable_string::~wipeable_string()
|
||||||
|
|
||||||
void wipeable_string::wipe()
|
void wipeable_string::wipe()
|
||||||
{
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(wipefunc, "wipefunc is not set");
|
memwipe(buffer.data(), buffer.size() * sizeof(char));
|
||||||
wipefunc(buffer.data(), buffer.size() * sizeof(char));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wipeable_string::grow(size_t sz, size_t reserved)
|
void wipeable_string::grow(size_t sz, size_t reserved)
|
||||||
{
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(wipefunc, "wipefunc is not set");
|
|
||||||
if (reserved < sz)
|
if (reserved < sz)
|
||||||
reserved = sz;
|
reserved = sz;
|
||||||
if (reserved <= buffer.capacity())
|
if (reserved <= buffer.capacity())
|
||||||
{
|
{
|
||||||
if (sz < buffer.size())
|
if (sz < buffer.size())
|
||||||
wipefunc(buffer.data() + sz, buffer.size() - sz);
|
memwipe(buffer.data() + sz, buffer.size() - sz);
|
||||||
buffer.resize(sz);
|
buffer.resize(sz);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t old_sz = buffer.size();
|
size_t old_sz = buffer.size();
|
||||||
std::unique_ptr<char[]> tmp{new char[old_sz]};
|
std::unique_ptr<char[]> tmp{new char[old_sz]};
|
||||||
memcpy(tmp.get(), buffer.data(), old_sz * sizeof(char));
|
memcpy(tmp.get(), buffer.data(), old_sz * sizeof(char));
|
||||||
wipefunc(buffer.data(), old_sz * sizeof(char));
|
memwipe(buffer.data(), old_sz * sizeof(char));
|
||||||
buffer.reserve(reserved);
|
buffer.reserve(reserved);
|
||||||
buffer.resize(sz);
|
buffer.resize(sz);
|
||||||
memcpy(buffer.data(), tmp.get(), old_sz * sizeof(char));
|
memcpy(buffer.data(), tmp.get(), old_sz * sizeof(char));
|
||||||
wipefunc(tmp.get(), old_sz * sizeof(char));
|
memwipe(tmp.get(), old_sz * sizeof(char));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wipeable_string::push_back(char c)
|
void wipeable_string::push_back(char c)
|
||||||
|
|
|
@ -552,8 +552,6 @@ std::string get_nix_version_display_string()
|
||||||
}
|
}
|
||||||
bool on_startup()
|
bool on_startup()
|
||||||
{
|
{
|
||||||
wipeable_string::set_wipe(&memwipe);
|
|
||||||
|
|
||||||
mlog_configure("", true);
|
mlog_configure("", true);
|
||||||
|
|
||||||
sanitize_locale();
|
sanitize_locale();
|
||||||
|
|
Loading…
Reference in a new issue