mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
wallet: Add BerkeleyDB version sanity check at init time
Detect version conflicts between the run-time BerkeleyDB library and the one used during compilation. This is very unsafe (can result in anything from crashes to corruption) so shut down when one is detected.
This commit is contained in:
parent
30e664dcce
commit
ad57fb756b
3 changed files with 26 additions and 0 deletions
|
@ -723,6 +723,23 @@ bool BerkeleyBatch::TxnAbort()
|
|||
return (ret == 0);
|
||||
}
|
||||
|
||||
bool BerkeleyDatabaseSanityCheck()
|
||||
{
|
||||
int major, minor;
|
||||
DbEnv::version(&major, &minor, nullptr);
|
||||
|
||||
/* If the major version differs, or the minor version of library is *older*
|
||||
* than the header that was compiled against, flag an error.
|
||||
*/
|
||||
if (major != DB_VERSION_MAJOR || minor < DB_VERSION_MINOR) {
|
||||
LogPrintf("BerkeleyDB database version conflict: header version is %d.%d, library version is %d.%d\n",
|
||||
DB_VERSION_MAJOR, DB_VERSION_MINOR, major, minor);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string BerkeleyDatabaseVersion()
|
||||
{
|
||||
return DbEnv::version(nullptr, nullptr, nullptr);
|
||||
|
|
|
@ -223,6 +223,10 @@ public:
|
|||
|
||||
std::string BerkeleyDatabaseVersion();
|
||||
|
||||
/** Perform sanity check of runtime BDB version versus linked BDB version.
|
||||
*/
|
||||
bool BerkeleyDatabaseSanityCheck();
|
||||
|
||||
//! Return object giving access to Berkeley database at specified path.
|
||||
std::unique_ptr<BerkeleyDatabase> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
|
||||
|
||||
|
|
|
@ -86,6 +86,11 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
|
|||
|
||||
bool WalletInit::ParameterInteraction() const
|
||||
{
|
||||
#ifdef USE_BDB
|
||||
if (!BerkeleyDatabaseSanityCheck()) {
|
||||
return InitError(Untranslated("A version conflict was detected between the run-time BerkeleyDB library and the one used during compilation."));
|
||||
}
|
||||
#endif
|
||||
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
|
||||
for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
|
||||
LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
|
||||
|
|
Loading…
Add table
Reference in a new issue