From 13976875d63e99570da004e14133ba66206bcad3 Mon Sep 17 00:00:00 2001 From: androm3da Date: Sun, 21 Jan 2018 16:38:39 -0600 Subject: [PATCH] Fix TOCTOU w/connection_frontier_request --- rai/node/bootstrap.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index b176341e..4f20e109 100644 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -1030,17 +1030,20 @@ void rai::bootstrap_attempt::requeue_pull (rai::pull_info const & pull_a) pulls.push_front (pull); condition.notify_all (); } - else if (pull.attempts == 4 && !connection_frontier_request.expired ()) + else if (pull.attempts == 4) { std::lock_guard lock (mutex); - auto connection_shared = connection_frontier_request.lock (); - auto client (std::make_shared (connection_shared)); - node->background ([client, pull]() { - client->request (pull); - }); - if (node->config.logging.bulk_pull_logging ()) + + if (auto connection_shared = connection_frontier_request.lock ()) { - BOOST_LOG (node->log) << boost::str (boost::format ("Requesting pull account %1% from frontier peer after %2% attempts") % pull.account.to_account () % pull.attempts); + auto client (std::make_shared (connection_shared)); + node->background ([client, pull]() { + client->request (pull); + }); + if (node->config.logging.bulk_pull_logging ()) + { + BOOST_LOG (node->log) << boost::str (boost::format ("Requesting pull account %1% from frontier peer after %2% attempts") % pull.account.to_account () % pull.attempts); + } } } else