diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-02-26 10:51:40 -0500 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-03-11 17:44:01 -0400 |
commit | c63996302e0f9fde3ca535347bbaf189d345ead6 (patch) | |
tree | 3abc6ee55eb707d5fd78883214c0ccca8f6492af | |
parent | a1c3fb582cd2d2df799f1d76e4b43e564bbb11b2 (diff) | |
download | mongo-c63996302e0f9fde3ca535347bbaf189d345ead6.tar.gz |
SERVER-39490 opWriteConcernCounters can cause undefined behavior due to overflow
(cherry picked from commit 884ac2862eda54e15d99e4db253b822cb4a90f1d)
-rw-r--r-- | src/mongo/db/stats/server_write_concern_metrics.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/stats/server_write_concern_metrics.h | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/mongo/db/stats/server_write_concern_metrics.cpp b/src/mongo/db/stats/server_write_concern_metrics.cpp index da8e74c9011..1477dac2f61 100644 --- a/src/mongo/db/stats/server_write_concern_metrics.cpp +++ b/src/mongo/db/stats/server_write_concern_metrics.cpp @@ -133,21 +133,21 @@ void ServerWriteConcernMetrics::WriteConcernMetricsForOperationType::recordWrite void ServerWriteConcernMetrics::WriteConcernMetricsForOperationType::toBSON( BSONObjBuilder* builder) const { - builder->append("wmajority", wMajorityCount); + builder->append("wmajority", static_cast<long long>(wMajorityCount)); BSONObjBuilder wNumBuilder(builder->subobjStart("wnum")); for (auto const& pair : wNumCounts) { - wNumBuilder.append(std::to_string(pair.first), pair.second); + wNumBuilder.append(std::to_string(pair.first), static_cast<long long>(pair.second)); } wNumBuilder.done(); BSONObjBuilder wTagBuilder(builder->subobjStart("wtag")); for (auto const& pair : wTagCounts) { - wTagBuilder.append(pair.first, pair.second); + wTagBuilder.append(pair.first, static_cast<long long>(pair.second)); } wTagBuilder.done(); - builder->append("none", noWCount); + builder->append("none", static_cast<long long>(noWCount)); } namespace { diff --git a/src/mongo/db/stats/server_write_concern_metrics.h b/src/mongo/db/stats/server_write_concern_metrics.h index db217dcdb7e..1ea8bc3e3ae 100644 --- a/src/mongo/db/stats/server_write_concern_metrics.h +++ b/src/mongo/db/stats/server_write_concern_metrics.h @@ -85,16 +85,16 @@ private: void toBSON(BSONObjBuilder* builder) const; // Count of operations with writeConcern w:"majority". - long long wMajorityCount = 0; + std::uint64_t wMajorityCount = 0; // Count of operations without a writeConcern "w" value. - long long noWCount = 0; + std::uint64_t noWCount = 0; // Counts of operations with writeConcern w:<num>. - std::map<int, long long> wNumCounts; + std::map<int, std::uint64_t> wNumCounts; // Counts of operations with writeConcern w:"tag". - StringMap<long long> wTagCounts; + StringMap<std::uint64_t> wTagCounts; }; mutable stdx::mutex _mutex; |