diff options
author | David Storch <david.storch@10gen.com> | 2015-10-29 14:07:25 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-10-29 18:05:22 -0400 |
commit | f95d12b1e033bc77713cabc32b51d0e2e347d828 (patch) | |
tree | 7877ffb7244baaec60043417cf4542be65631c5e /src/mongo/db/catalog/index_key_validate.cpp | |
parent | d75f311d37b5710421668425bbdf703c0b3324e7 (diff) | |
download | mongo-f95d12b1e033bc77713cabc32b51d0e2e347d828.tar.gz |
SERVER-21166 validate that index key pattern values are representable as 32-bit signed numbers
Diffstat (limited to 'src/mongo/db/catalog/index_key_validate.cpp')
-rw-r--r-- | src/mongo/db/catalog/index_key_validate.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp index d29c4d93d92..570f246f35e 100644 --- a/src/mongo/db/catalog/index_key_validate.cpp +++ b/src/mongo/db/catalog/index_key_validate.cpp @@ -26,8 +26,12 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/db/catalog/index_key_validate.h" +#include <limits> + #include "mongo/db/field_ref.h" #include "mongo/db/index_names.h" #include "mongo/db/jsobj.h" @@ -64,6 +68,17 @@ Status validateKeyPattern(const BSONObj& key) { return Status(code, "Can't use more than one index plugin for a single index."); } + // We convert the element value to an int in order to determine whether the index is + // ascending or descending on a particular field. Therefore, the element value cannot + // overflow an int. + long long asLong = keyElement.safeNumberLong(); + if (asLong > std::numeric_limits<int>::max() || asLong < std::numeric_limits<int>::min()) { + return Status(code, + str::stream() + << "Key pattern element cannot be represented as a 32-bit int: " + << keyElement); + } + // Ensure that the fields on which we are building the index are valid: a field must not // begin with a '$' unless it is part of a DBRef or text index, and a field path cannot // contain an empty field. If a field cannot be created or updated, it should not be |