From b7ee6073124d100f2d5405cc9952f83ba9704222 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 19 Dec 2017 10:10:05 +0100 Subject: [PATCH] Bug fix 3.3/integer overflow when calculating waits in constituent (#4090) * integer overflow in Constituent could seize operation of Agency * less likely integer overflow on double conversion * less likely integer overflow on double conversion * changed comparison to integer comparison as suggested by @neunhoef --- arangod/Agency/AgencyComm.cpp | 10 +++++----- arangod/Agency/AgencyComm.h | 2 +- arangod/Agency/Constituent.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arangod/Agency/AgencyComm.cpp b/arangod/Agency/AgencyComm.cpp index c429a00336..f38b869e4f 100644 --- a/arangod/Agency/AgencyComm.cpp +++ b/arangod/Agency/AgencyComm.cpp @@ -819,7 +819,7 @@ AgencyCommResult AgencyComm::setValue(std::string const& key, AgencyOperation operation(key, AgencyValueOperationType::SET, builder.slice()); - operation._ttl = static_cast(ttl); + operation._ttl = static_cast(ttl); AgencyWriteTransaction transaction(operation); return sendTransactionWithFailover(transaction); @@ -829,7 +829,7 @@ AgencyCommResult AgencyComm::setValue(std::string const& key, arangodb::velocypack::Slice const& slice, double ttl) { AgencyOperation operation(key, AgencyValueOperationType::SET, slice); - operation._ttl = static_cast(ttl); + operation._ttl = static_cast(ttl); AgencyWriteTransaction transaction(operation); return sendTransactionWithFailover(transaction); @@ -839,7 +839,7 @@ AgencyCommResult AgencyComm::setTransient(std::string const& key, arangodb::velocypack::Slice const& slice, double ttl) { AgencyOperation operation(key, AgencyValueOperationType::SET, slice); - operation._ttl = static_cast(ttl); + operation._ttl = static_cast(ttl); AgencyTransientTransaction transaction(operation); return sendTransactionWithFailover(transaction); @@ -938,7 +938,7 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, AgencyPrecondition precondition(key, AgencyPrecondition::Type::EMPTY, !prevExist); if (ttl >= 0.0) { - operation._ttl = static_cast(ttl); + operation._ttl = static_cast(ttl); } VPackBuilder preBuilder; @@ -963,7 +963,7 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, AgencyPrecondition precondition(key, AgencyPrecondition::Type::VALUE, oldBuilder.slice()); if (ttl >= 0.0) { - operation._ttl = static_cast(ttl); + operation._ttl = static_cast(ttl); } AgencyWriteTransaction transaction(operation, precondition); diff --git a/arangod/Agency/AgencyComm.h b/arangod/Agency/AgencyComm.h index 5bb56f2b9b..b92271c2d0 100644 --- a/arangod/Agency/AgencyComm.h +++ b/arangod/Agency/AgencyComm.h @@ -204,7 +204,7 @@ class AgencyOperation { AgencyOperationType type() const; public: - uint32_t _ttl = 0; + uint64_t _ttl = 0; VPackSlice _oldValue; private: diff --git a/arangod/Agency/Constituent.cpp b/arangod/Agency/Constituent.cpp index 7e31ee536d..027ad662d0 100644 --- a/arangod/Agency/Constituent.cpp +++ b/arangod/Agency/Constituent.cpp @@ -702,7 +702,7 @@ void Constituent::run() { LOG_TOPIC(TRACE, Logger::AGENCY) << "Random timeout: " << randTimeout << ", wait: " << randWait; - if (randWait > 0.0) { + if (randWait > 0) { CONDITION_LOCKER(guardv, _cv); _cv.wait(randWait); } @@ -719,7 +719,7 @@ void Constituent::run() { double diff = TRI_microtime() - _lastHeartbeatSeen; LOG_TOPIC(TRACE, Logger::AGENCY) << "last heartbeat: " << diff << "sec ago"; - isTimeout = (static_cast(M * diff) > randTimeout); + isTimeout = (static_cast(M * diff) > randTimeout); } }