Fix ASAN warning caused by global initialization order using CryptoPP functions (#1747)

* Fix ASAN warning by doing lazy initialization

* Make a local reference and remove unrelated circular buffer changes

* Remove other unrelated change
This commit is contained in:
Wesley Shillingford 2019-02-19 13:13:16 +00:00 committed by GitHub
commit c0356a4e21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 16 deletions

View file

@ -1212,7 +1212,8 @@ void nano::mdb_store::upgrade_v12_to_v13 (size_t const batch_size)
size_t cost (0);
nano::account account (0);
auto transaction (tx_begin_write ());
while (!stopped && account != nano::not_an_account)
auto const & not_an_account (nano::not_an_account ());
while (!stopped && account != not_an_account)
{
nano::account first (0);
nano::account_info second;
@ -1261,10 +1262,10 @@ void nano::mdb_store::upgrade_v12_to_v13 (size_t const batch_size)
}
else
{
account = nano::not_an_account;
account = not_an_account;
}
}
if (account == nano::not_an_account)
if (account == not_an_account)
{
BOOST_LOG (logging.log) << boost::str (boost::format ("Completed sideband upgrade"));
version_put (transaction, 13);

View file

@ -3021,7 +3021,7 @@ confirmed (false),
stopped (false),
announcements (0)
{
last_votes.insert (std::make_pair (nano::not_an_account, nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () }));
last_votes.insert (std::make_pair (nano::not_an_account (), nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () }));
blocks.insert (std::make_pair (block_a->hash (), block_a));
}

View file

@ -64,10 +64,6 @@ public:
genesis_amount (std::numeric_limits<nano::uint128_t>::max ()),
burn_account (0)
{
CryptoPP::AutoSeededRandomPool random_pool;
// Randomly generating these mean no two nodes will ever have the same sentinel values which protects against some insecure algorithms
random_pool.GenerateBlock (not_a_block.bytes.data (), not_a_block.bytes.size ());
random_pool.GenerateBlock (not_an_account.bytes.data (), not_an_account.bytes.size ());
}
nano::keypair zero_key;
nano::keypair test_genesis_key;
@ -80,9 +76,24 @@ public:
nano::account genesis_account;
std::string genesis_block;
nano::uint128_t genesis_amount;
nano::block_hash not_a_block;
nano::account not_an_account;
nano::account burn_account;
nano::account const & not_an_account ()
{
static bool is_initialized = false;
static std::mutex mutex;
std::lock_guard<std::mutex> lk (mutex);
if (!is_initialized)
{
// Randomly generating these mean no two nodes will ever have the same sentinel values which protects against some insecure algorithms
nano::random_pool.GenerateBlock (not_an_account_m.bytes.data (), not_an_account_m.bytes.size ());
is_initialized = true;
}
return not_an_account_m;
}
private:
nano::account not_an_account_m;
};
ledger_constants globals;
}
@ -105,10 +116,11 @@ std::string const & nano::nano_live_genesis (globals.nano_live_genesis);
nano::account const & nano::genesis_account (globals.genesis_account);
std::string const & nano::genesis_block (globals.genesis_block);
nano::uint128_t const & nano::genesis_amount (globals.genesis_amount);
nano::block_hash const & nano::not_a_block (globals.not_a_block);
nano::block_hash const & nano::not_an_account (globals.not_an_account);
nano::account const & nano::burn_account (globals.burn_account);
nano::account const & nano::not_an_account ()
{
return globals.not_an_account ();
}
// Create a new random keypair
nano::keypair::keypair ()
{

View file

@ -320,10 +320,8 @@ extern std::string const & genesis_block;
extern nano::account const & genesis_account;
extern nano::account const & burn_account;
extern nano::uint128_t const & genesis_amount;
// A block hash that compares inequal to any real block hash
extern nano::block_hash const & not_a_block;
// An account number that compares inequal to any real account number
extern nano::block_hash const & not_an_account;
extern nano::account const & not_an_account ();
class genesis
{
public: