summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-12-14 18:22:01 -0500
committerDavid Storch <david.storch@10gen.com>2015-12-22 10:13:40 -0500
commit26bcf4ddd7e86885448e981f86aaf51fba0e2539 (patch)
tree5d9cd1de1193f8c52f8d1eae3dd3e35a3bffd3f0 /src/mongo/db/commands
parent3663e004dfc2f73b82b3d88b5fa1ac6b7dcd1d33 (diff)
downloadmongo-26bcf4ddd7e86885448e981f86aaf51fba0e2539.tar.gz
SERVER-21407 explicitly disallow $text/$where extensions during MatchExpression parsing
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/index_filter_commands_test.cpp13
-rw-r--r--src/mongo/db/commands/list_collections.cpp5
-rw-r--r--src/mongo/db/commands/plan_cache_commands_test.cpp19
3 files changed, 26 insertions, 11 deletions
diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp
index 5a0d7b6ce07..463f1bb117e 100644
--- a/src/mongo/db/commands/index_filter_commands_test.cpp
+++ b/src/mongo/db/commands/index_filter_commands_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/json.h"
+#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/db/query/plan_ranker.h"
#include "mongo/db/query/query_solution.h"
@@ -120,7 +121,8 @@ void addQueryShapeToPlanCache(PlanCache* planCache,
BSONObj projectionObj = fromjson(projectionStr);
// Create canonical query.
- auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projectionObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(
+ nss, queryObj, sortObj, projectionObj, ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -144,7 +146,8 @@ bool planCacheContains(const PlanCache& planCache,
BSONObj projectionObj = fromjson(projectionStr);
// Create canonical query.
- auto statusWithInputQuery = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projectionObj);
+ auto statusWithInputQuery = CanonicalQuery::canonicalize(
+ nss, queryObj, sortObj, projectionObj, ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithInputQuery.getStatus());
unique_ptr<CanonicalQuery> inputQuery = std::move(statusWithInputQuery.getValue());
@@ -160,7 +163,11 @@ bool planCacheContains(const PlanCache& planCache,
// Alternatively, we could add key to PlanCacheEntry but that would be used in one place
// only.
auto statusWithCurrentQuery =
- CanonicalQuery::canonicalize(nss, entry->query, entry->sort, entry->projection);
+ CanonicalQuery::canonicalize(nss,
+ entry->query,
+ entry->sort,
+ entry->projection,
+ ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCurrentQuery.getStatus());
unique_ptr<CanonicalQuery> currentQuery = std::move(statusWithCurrentQuery.getValue());
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 76ccfa77ea5..f467c14b3df 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/db_raii.h"
#include "mongo/db/exec/queued_data_stage.h"
#include "mongo/db/exec/working_set.h"
+#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/find_common.h"
#include "mongo/db/service_context.h"
@@ -192,8 +193,8 @@ public:
return appendCommandStatus(
result, Status(ErrorCodes::BadValue, "\"filter\" must be an object"));
}
- StatusWithMatchExpression statusWithMatcher =
- MatchExpressionParser::parse(filterElt.Obj());
+ StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(
+ filterElt.Obj(), ExtensionsCallbackDisallowExtensions());
if (!statusWithMatcher.isOK()) {
return appendCommandStatus(result, statusWithMatcher.getStatus());
}
diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp
index 7ffe832473b..7234588fd37 100644
--- a/src/mongo/db/commands/plan_cache_commands_test.cpp
+++ b/src/mongo/db/commands/plan_cache_commands_test.cpp
@@ -35,6 +35,7 @@
#include <algorithm>
#include "mongo/db/json.h"
+#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/db/query/plan_ranker.h"
#include "mongo/db/query/query_solution.h"
@@ -125,7 +126,8 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesEmpty) {
TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(
+ nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -150,7 +152,8 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) {
TEST(PlanCacheCommandsTest, planCacheClearAllShapes) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(
+ nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -266,10 +269,12 @@ TEST(PlanCacheCommandsTest, planCacheClearUnknownKey) {
TEST(PlanCacheCommandsTest, planCacheClearOneKey) {
// Create 2 canonical queries.
- auto statusWithCQA = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
+ auto statusWithCQA = CanonicalQuery::canonicalize(
+ nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQA.getStatus());
unique_ptr<CanonicalQuery> cqA = std::move(statusWithCQA.getValue());
- auto statusWithCQB = CanonicalQuery::canonicalize(nss, fromjson("{b: 1}"));
+ auto statusWithCQB = CanonicalQuery::canonicalize(
+ nss, fromjson("{b: 1}"), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQB.getStatus());
unique_ptr<CanonicalQuery> cqB = std::move(statusWithCQB.getValue());
@@ -388,7 +393,8 @@ TEST(PlanCacheCommandsTest, planCacheListPlansUnknownKey) {
TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(
+ nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -407,7 +413,8 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) {
TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionFalse) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(
+ nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());