|
|
|
@ -180,22 +180,23 @@ public:
@@ -180,22 +180,23 @@ public:
|
|
|
|
|
Dbt datValue; |
|
|
|
|
datValue.set_flags(DB_DBT_MALLOC); |
|
|
|
|
int ret = pdb->get(activeTxn, &datKey, &datValue, 0); |
|
|
|
|
memset(datKey.get_data(), 0, datKey.get_size()); |
|
|
|
|
if (datValue.get_data() == NULL) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
memory_cleanse(datKey.get_data(), datKey.get_size()); |
|
|
|
|
bool success = false; |
|
|
|
|
if (datValue.get_data() != NULL) { |
|
|
|
|
// Unserialize value
|
|
|
|
|
try { |
|
|
|
|
CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK, CLIENT_VERSION); |
|
|
|
|
ssValue >> value; |
|
|
|
|
success = true; |
|
|
|
|
} catch (const std::exception&) { |
|
|
|
|
return false; |
|
|
|
|
// In this case success remains 'false'
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Clear and free memory
|
|
|
|
|
memset(datValue.get_data(), 0, datValue.get_size()); |
|
|
|
|
memory_cleanse(datValue.get_data(), datValue.get_size()); |
|
|
|
|
free(datValue.get_data()); |
|
|
|
|
return (ret == 0); |
|
|
|
|
} |
|
|
|
|
return ret == 0 && success; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename K, typename T> |
|
|
|
@ -222,8 +223,8 @@ public:
@@ -222,8 +223,8 @@ public:
|
|
|
|
|
int ret = pdb->put(activeTxn, &datKey, &datValue, (fOverwrite ? 0 : DB_NOOVERWRITE)); |
|
|
|
|
|
|
|
|
|
// Clear memory in case it was a private key
|
|
|
|
|
memset(datKey.get_data(), 0, datKey.get_size()); |
|
|
|
|
memset(datValue.get_data(), 0, datValue.get_size()); |
|
|
|
|
memory_cleanse(datKey.get_data(), datKey.get_size()); |
|
|
|
|
memory_cleanse(datValue.get_data(), datValue.get_size()); |
|
|
|
|
return (ret == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -245,7 +246,7 @@ public:
@@ -245,7 +246,7 @@ public:
|
|
|
|
|
int ret = pdb->del(activeTxn, &datKey, 0); |
|
|
|
|
|
|
|
|
|
// Clear memory
|
|
|
|
|
memset(datKey.get_data(), 0, datKey.get_size()); |
|
|
|
|
memory_cleanse(datKey.get_data(), datKey.get_size()); |
|
|
|
|
return (ret == 0 || ret == DB_NOTFOUND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -265,7 +266,7 @@ public:
@@ -265,7 +266,7 @@ public:
|
|
|
|
|
int ret = pdb->exists(activeTxn, &datKey, 0); |
|
|
|
|
|
|
|
|
|
// Clear memory
|
|
|
|
|
memset(datKey.get_data(), 0, datKey.get_size()); |
|
|
|
|
memory_cleanse(datKey.get_data(), datKey.get_size()); |
|
|
|
|
return (ret == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -308,8 +309,8 @@ public:
@@ -308,8 +309,8 @@ public:
|
|
|
|
|
ssValue.write((char*)datValue.get_data(), datValue.get_size()); |
|
|
|
|
|
|
|
|
|
// Clear and free memory
|
|
|
|
|
memset(datKey.get_data(), 0, datKey.get_size()); |
|
|
|
|
memset(datValue.get_data(), 0, datValue.get_size()); |
|
|
|
|
memory_cleanse(datKey.get_data(), datKey.get_size()); |
|
|
|
|
memory_cleanse(datValue.get_data(), datValue.get_size()); |
|
|
|
|
free(datKey.get_data()); |
|
|
|
|
free(datValue.get_data()); |
|
|
|
|
return 0; |
|
|
|
|