-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Introduce SafeDbt to handle Dbt with free or memory_cleanse raii-style #14268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,6 +247,45 @@ BerkeleyEnvironment::VerifyResult BerkeleyEnvironment::Verify(const std::string& | |
| return (fRecovered ? VerifyResult::RECOVER_OK : VerifyResult::RECOVER_FAIL); | ||
| } | ||
|
|
||
| BerkeleyBatch::SafeDbt::SafeDbt() | ||
| { | ||
| m_dbt.set_flags(DB_DBT_MALLOC); | ||
| } | ||
|
|
||
| BerkeleyBatch::SafeDbt::SafeDbt(void* data, size_t size) | ||
| : m_dbt(data, size) | ||
| { | ||
| } | ||
|
|
||
| BerkeleyBatch::SafeDbt::~SafeDbt() | ||
| { | ||
| if (m_dbt.get_data() != nullptr) { | ||
| // Clear memory, e.g. in case it was a private key | ||
| memory_cleanse(m_dbt.get_data(), m_dbt.get_size()); | ||
| // under DB_DBT_MALLOC, data is malloced by the Dbt, but must be | ||
| // freed by the caller. | ||
| // https://docs.oracle.com/cd/E17275_01/html/api_reference/C/dbt.html | ||
| if (m_dbt.get_flags() & DB_DBT_MALLOC) { | ||
| free(m_dbt.get_data()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const void* BerkeleyBatch::SafeDbt::get_data() const | ||
| { | ||
| return m_dbt.get_data(); | ||
| } | ||
|
|
||
| u_int32_t BerkeleyBatch::SafeDbt::get_size() const | ||
| { | ||
| return m_dbt.get_size(); | ||
| } | ||
|
|
||
| BerkeleyBatch::SafeDbt::operator Dbt*() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's returning a mutable pointer to the internal structure, I don't think it'd make sense to make the method const (unless you mean it should return a |
||
| { | ||
| return &m_dbt; | ||
| } | ||
|
|
||
| bool BerkeleyBatch::Recover(const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& newFilename) | ||
| { | ||
| std::string filename; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes behavior: in the case of
Writeit was also cleansing the dtabase key, now it no longer is.Not sure if this is necessary, I don't think the database keys ever contain sensitive information, but it should be noted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is cleansing the key - if you're referring to the cleansing here:
https://github.com/bitcoin/bitcoin/pull/14268/files#diff-c557c8e6d496041acccfd8ac4e3db625L257
Then the key and value are separate
SafeDbtobjects, with each managing/cleansing its own data:https://github.com/bitcoin/bitcoin/pull/14268/files#diff-c557c8e6d496041acccfd8ac4e3db625R258
https://github.com/bitcoin/bitcoin/pull/14268/files#diff-c557c8e6d496041acccfd8ac4e3db625R264