diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2020-07-28 16:14:19 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-30 19:55:16 +0000 |
commit | 961af6d38fd9ae237b5a57991374b71d2f2551be (patch) | |
tree | 32cdd8ce223296f92c90b4e9b7bb976417ed00fc | |
parent | 5aa7067d9e1c36cd89c49d906a79c9f51b8cdac0 (diff) | |
download | mongo-961af6d38fd9ae237b5a57991374b71d2f2551be.tar.gz |
SERVER-49957 Fix read out of bounds in dbCheck getPrevAndNextUUIDs when we operate on first element
(cherry picked from commit 41fda13f7239308239ade7f143f9b5e2fef0e87b)
-rw-r--r-- | src/mongo/db/repl/dbcheck.cpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/mongo/db/repl/dbcheck.cpp b/src/mongo/db/repl/dbcheck.cpp index a69b2c07e71..1958223c197 100644 --- a/src/mongo/db/repl/dbcheck.cpp +++ b/src/mongo/db/repl/dbcheck.cpp @@ -242,17 +242,14 @@ std::pair<boost::optional<UUID>, boost::optional<UUID>> getPrevAndNextUUIDs( auto uuidIt = std::find(collectionUUIDs.begin(), collectionUUIDs.end(), uuid); invariant(uuidIt != collectionUUIDs.end()); - auto prevIt = std::prev(uuidIt); - auto nextIt = std::next(uuidIt); - boost::optional<UUID> prevUUID; boost::optional<UUID> nextUUID; - if (prevIt != collectionUUIDs.end()) { - prevUUID = *prevIt; + if (uuidIt != collectionUUIDs.begin()) { + prevUUID = *std::prev(uuidIt); } - if (nextIt != collectionUUIDs.end()) { + if (auto nextIt = std::next(uuidIt); nextIt != collectionUUIDs.end()) { nextUUID = *nextIt; } |