diff options
author | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-03-13 12:16:34 -0400 |
---|---|---|
committer | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-03-13 12:16:45 -0400 |
commit | d98143c5db73a8a9a49ef20e9e0f2732b4de5063 (patch) | |
tree | d413ea7a3eb37e24e78dfffeaec6ad9453ff6615 /src/mongo/db/matcher/expression_parser.h | |
parent | 259fed1b72cf3145948068002bdb2cdb94b40d0d (diff) | |
download | mongo-d98143c5db73a8a9a49ef20e9e0f2732b4de5063.tar.gz |
SERVER-26703 reject commands exceeding the BSON depth limit
Any command sent to the server that exceeds the depth limit will fail. This also prevents users from
inserting documents that exceed the depth limit.
Diffstat (limited to 'src/mongo/db/matcher/expression_parser.h')
-rw-r--r-- | src/mongo/db/matcher/expression_parser.h | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/mongo/db/matcher/expression_parser.h b/src/mongo/db/matcher/expression_parser.h index 9df3a7aa874..8141726251b 100644 --- a/src/mongo/db/matcher/expression_parser.h +++ b/src/mongo/db/matcher/expression_parser.h @@ -52,8 +52,8 @@ public: static StatusWithMatchExpression parse(const BSONObj& obj, const ExtensionsCallback& extensionsCallback, const CollatorInterface* collator) { - // The 0 initializes the match expression tree depth. - return MatchExpressionParser(&extensionsCallback)._parse(obj, collator, 0); + const bool topLevelCall = true; + return MatchExpressionParser(&extensionsCallback)._parse(obj, collator, topLevelCall); } private: @@ -86,13 +86,12 @@ private: * 'collator' is the collator that constructed collation-aware MatchExpressions will use. It * must outlive the returned MatchExpression and any clones made of it. * - * 'level' tracks the current depth of the tree across recursive calls to this - * function. Used in order to apply special logic at the top-level and to return an - * error if the tree exceeds the maximum allowed depth. + * 'topLevel' indicates whether or not the we are at the top level of the tree across recursive + * class to this function. This is used to apply special logic at the top level. */ StatusWithMatchExpression _parse(const BSONObj& obj, const CollatorInterface* collator, - int level); + bool topLevel); /** * parses a field in a sub expression @@ -103,7 +102,7 @@ private: const BSONObj& obj, AndMatchExpression* root, const CollatorInterface* collator, - int level); + bool topLevel); /** * parses a single field in a sub expression @@ -115,7 +114,7 @@ private: const char* name, const BSONElement& e, const CollatorInterface* collator, - int level); + bool topLevel); StatusWithMatchExpression _parseComparison(const char* name, ComparisonMatchExpression* cmp, @@ -140,24 +139,24 @@ private: StatusWithMatchExpression _parseElemMatch(const char* name, const BSONElement& e, const CollatorInterface* collator, - int level); + bool topLevel); StatusWithMatchExpression _parseAll(const char* name, const BSONElement& e, const CollatorInterface* collator, - int level); + bool topLevel); // tree Status _parseTreeList(const BSONObj& arr, ListOfMatchExpression* out, const CollatorInterface* collator, - int level); + bool topLevel); StatusWithMatchExpression _parseNot(const char* name, const BSONElement& e, const CollatorInterface* collator, - int level); + bool topLevel); /** * Parses 'e' into a BitTestMatchExpression. |