From b19f95495d1df437722e6a0c85ea5ca6f91cdd8b Mon Sep 17 00:00:00 2001 From: Tess Avitabile Date: Mon, 21 Aug 2017 15:31:06 -0400 Subject: SERVER-29840 Add allowed features bitmask to MatchExpressionParser::parse --- src/mongo/db/commands/apply_ops_cmd.cpp | 1 - src/mongo/db/commands/dbcommands.cpp | 4 +-- src/mongo/db/commands/find_cmd.cpp | 17 ++++++++++-- src/mongo/db/commands/geo_near_cmd.cpp | 9 ++++++- src/mongo/db/commands/index_filter_commands.cpp | 9 ++++++- .../db/commands/index_filter_commands_test.cpp | 10 +++---- src/mongo/db/commands/list_collections.cpp | 5 ++-- src/mongo/db/commands/list_databases.cpp | 4 +-- src/mongo/db/commands/mr.cpp | 20 +++++++++++--- src/mongo/db/commands/plan_cache_commands.cpp | 9 ++++++- src/mongo/db/commands/plan_cache_commands_test.cpp | 31 +++++++--------------- 11 files changed, 72 insertions(+), 47 deletions(-) (limited to 'src/mongo/db/commands') diff --git a/src/mongo/db/commands/apply_ops_cmd.cpp b/src/mongo/db/commands/apply_ops_cmd.cpp index 504abd19079..e2c0d9c6f4a 100644 --- a/src/mongo/db/commands/apply_ops_cmd.cpp +++ b/src/mongo/db/commands/apply_ops_cmd.cpp @@ -43,7 +43,6 @@ #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/jsobj.h" -#include "mongo/db/matcher/matcher.h" #include "mongo/db/operation_context.h" #include "mongo/db/repl/apply_ops.h" #include "mongo/db/repl/oplog.h" diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index ef4ddac6eb1..f5cc3803928 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -74,7 +74,6 @@ #include "mongo/db/json.h" #include "mongo/db/keypattern.h" #include "mongo/db/lasterror.h" -#include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/namespace_string.h" #include "mongo/db/op_observer.h" #include "mongo/db/ops/insert.h" @@ -696,8 +695,7 @@ public: qr->setFilter(query); qr->setSort(sort); - auto statusWithCQ = CanonicalQuery::canonicalize( - opCtx, std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr)); if (!statusWithCQ.isOK()) { uasserted(17240, "Can't canonicalize query " + query.toString()); return false; diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index f54dbbbf312..fe1d0940ff9 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -151,8 +151,14 @@ public: // Finish the parsing step by using the QueryRequest to create a CanonicalQuery. ExtensionsCallbackReal extensionsCallback(opCtx, &nss); + const boost::intrusive_ptr expCtx; auto statusWithCQ = - CanonicalQuery::canonicalize(opCtx, std::move(qrStatus.getValue()), extensionsCallback); + CanonicalQuery::canonicalize(opCtx, + std::move(qrStatus.getValue()), + expCtx, + extensionsCallback, + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); if (!statusWithCQ.isOK()) { return statusWithCQ.getStatus(); } @@ -257,7 +263,14 @@ public: // Finish the parsing step by using the QueryRequest to create a CanonicalQuery. ExtensionsCallbackReal extensionsCallback(opCtx, &nss); - auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr), extensionsCallback); + const boost::intrusive_ptr expCtx; + auto statusWithCQ = + CanonicalQuery::canonicalize(opCtx, + std::move(qr), + expCtx, + extensionsCallback, + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); if (!statusWithCQ.isOK()) { return appendCommandStatus(result, statusWithCQ.getStatus()); } diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp index 2a5c5c32d6c..02a57e7d0e8 100644 --- a/src/mongo/db/commands/geo_near_cmd.cpp +++ b/src/mongo/db/commands/geo_near_cmd.cpp @@ -215,7 +215,14 @@ public: qr->setLimit(numWanted); qr->setCollation(collation); const ExtensionsCallbackReal extensionsCallback(opCtx, &nss); - auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr), extensionsCallback); + const boost::intrusive_ptr expCtx; + auto statusWithCQ = + CanonicalQuery::canonicalize(opCtx, + std::move(qr), + expCtx, + extensionsCallback, + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); if (!statusWithCQ.isOK()) { errmsg = "Can't parse filter / create query"; return false; diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp index c7e3b2043bc..1992f122edc 100644 --- a/src/mongo/db/commands/index_filter_commands.cpp +++ b/src/mongo/db/commands/index_filter_commands.cpp @@ -310,7 +310,14 @@ Status ClearFilters::clear(OperationContext* opCtx, qr->setSort(entry.sort); qr->setProj(entry.projection); qr->setCollation(entry.collation); - auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr), extensionsCallback); + const boost::intrusive_ptr expCtx; + auto statusWithCQ = + CanonicalQuery::canonicalize(opCtx, + std::move(qr), + expCtx, + extensionsCallback, + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); invariantOK(statusWithCQ.getStatus()); std::unique_ptr cq = std::move(statusWithCQ.getValue()); diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp index e182aabe539..17dec1cb003 100644 --- a/src/mongo/db/commands/index_filter_commands_test.cpp +++ b/src/mongo/db/commands/index_filter_commands_test.cpp @@ -33,7 +33,6 @@ #include "mongo/db/commands/index_filter_commands.h" #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/collation/collator_interface_mock.h" #include "mongo/db/query/plan_ranker.h" @@ -132,8 +131,7 @@ void addQueryShapeToPlanCache(OperationContext* opCtx, qr->setSort(fromjson(sortStr)); qr->setProj(fromjson(projectionStr)); qr->setCollation(fromjson(collationStr)); - auto statusWithCQ = - CanonicalQuery::canonicalize(opCtx, std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr)); ASSERT_OK(statusWithCQ.getStatus()); std::unique_ptr cq = std::move(statusWithCQ.getValue()); @@ -162,8 +160,7 @@ bool planCacheContains(const PlanCache& planCache, qr->setSort(fromjson(sortStr)); qr->setProj(fromjson(projectionStr)); qr->setCollation(fromjson(collationStr)); - auto statusWithInputQuery = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithInputQuery = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithInputQuery.getStatus()); unique_ptr inputQuery = std::move(statusWithInputQuery.getValue()); @@ -183,8 +180,7 @@ bool planCacheContains(const PlanCache& planCache, qr->setSort(entry->sort); qr->setProj(entry->projection); qr->setCollation(entry->collation); - auto statusWithCurrentQuery = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCurrentQuery = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithCurrentQuery.getStatus()); unique_ptr currentQuery = std::move(statusWithCurrentQuery.getValue()); diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index 6a619a43861..c952573ac14 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -49,7 +49,6 @@ #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/index/index_descriptor.h" -#include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/query/cursor_request.h" #include "mongo/db/query/cursor_response.h" #include "mongo/db/query/find_common.h" @@ -245,8 +244,8 @@ public: } // The collator is null because collection objects are compared using binary comparison. const CollatorInterface* collator = nullptr; - StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse( - filterElt.Obj(), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression statusWithMatcher = + MatchExpressionParser::parse(filterElt.Obj(), collator); if (!statusWithMatcher.isOK()) { return appendCommandStatus(result, statusWithMatcher.getStatus()); } diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp index b25a13b887b..232803320d0 100644 --- a/src/mongo/db/commands/list_databases.cpp +++ b/src/mongo/db/commands/list_databases.cpp @@ -35,7 +35,6 @@ #include "mongo/db/commands.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/matcher/expression.h" -#include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/storage_engine.h" @@ -100,8 +99,7 @@ public: // The collator is null because database metadata objects are compared using simple // binary comparison. const CollatorInterface* collator = nullptr; - auto statusWithMatcher = MatchExpressionParser::parse( - filterElt.Obj(), ExtensionsCallbackDisallowExtensions(), collator); + auto statusWithMatcher = MatchExpressionParser::parse(filterElt.Obj(), collator); if (!statusWithMatcher.isOK()) { return appendCommandStatus(result, statusWithMatcher.getStatus()); } diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index 580918250a0..3cfbad4b4c7 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -53,7 +53,6 @@ #include "mongo/db/exec/working_set_common.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/matcher/extensions_callback_real.h" -#include "mongo/db/matcher/matcher.h" #include "mongo/db/op_observer.h" #include "mongo/db/ops/insert.h" #include "mongo/db/query/find_common.h" @@ -1096,7 +1095,14 @@ void State::finalReduce(OperationContext* opCtx, CurOp* curOp, ProgressMeterHold auto qr = stdx::make_unique(_config.incLong); qr->setSort(sortKey); - auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr), extensionsCallback); + const boost::intrusive_ptr expCtx; + auto statusWithCQ = + CanonicalQuery::canonicalize(opCtx, + std::move(qr), + expCtx, + extensionsCallback, + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); verify(statusWithCQ.isOK()); std::unique_ptr cq = std::move(statusWithCQ.getValue()); @@ -1464,8 +1470,14 @@ public: const ExtensionsCallbackReal extensionsCallback(opCtx, &config.nss); - auto statusWithCQ = - CanonicalQuery::canonicalize(opCtx, std::move(qr), extensionsCallback); + const boost::intrusive_ptr expCtx; + auto statusWithCQ = CanonicalQuery::canonicalize( + opCtx, + std::move(qr), + expCtx, + extensionsCallback, + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); if (!statusWithCQ.isOK()) { uasserted(17238, "Can't canonicalize query " + config.filter.toString()); return 0; diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp index f66bc7392b2..031d59e408d 100644 --- a/src/mongo/db/commands/plan_cache_commands.cpp +++ b/src/mongo/db/commands/plan_cache_commands.cpp @@ -207,7 +207,14 @@ StatusWith> PlanCacheCommand::canonicalize(OperationC qr->setProj(projObj); qr->setCollation(collationObj); const ExtensionsCallbackReal extensionsCallback(opCtx, &nss); - auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr), extensionsCallback); + const boost::intrusive_ptr expCtx; + auto statusWithCQ = + CanonicalQuery::canonicalize(opCtx, + std::move(qr), + expCtx, + extensionsCallback, + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); if (!statusWithCQ.isOK()) { return statusWithCQ.getStatus(); } diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp index 97b3884f8cd..e8a80bf2266 100644 --- a/src/mongo/db/commands/plan_cache_commands_test.cpp +++ b/src/mongo/db/commands/plan_cache_commands_test.cpp @@ -35,7 +35,6 @@ #include #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" @@ -142,8 +141,7 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) { qr->setSort(fromjson("{a: -1}")); qr->setProj(fromjson("{_id: 0}")); qr->setCollation(fromjson("{locale: 'mock_reverse_string'}")); - auto statusWithCQ = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr cq = std::move(statusWithCQ.getValue()); @@ -174,8 +172,7 @@ TEST(PlanCacheCommandsTest, planCacheClearAllShapes) { // Create a canonical query auto qr = stdx::make_unique(nss); qr->setFilter(fromjson("{a: 1}")); - auto statusWithCQ = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr cq = std::move(statusWithCQ.getValue()); @@ -310,14 +307,12 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKey) { // Create 2 canonical queries. auto qrA = stdx::make_unique(nss); qrA->setFilter(fromjson("{a: 1}")); - auto statusWithCQA = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qrA), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQA = CanonicalQuery::canonicalize(opCtx.get(), std::move(qrA)); ASSERT_OK(statusWithCQA.getStatus()); auto qrB = stdx::make_unique(nss); qrB->setFilter(fromjson("{b: 1}")); unique_ptr cqA = std::move(statusWithCQA.getValue()); - auto statusWithCQB = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qrB), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQB = CanonicalQuery::canonicalize(opCtx.get(), std::move(qrB)); ASSERT_OK(statusWithCQB.getStatus()); unique_ptr cqB = std::move(statusWithCQB.getValue()); @@ -365,15 +360,13 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKeyCollation) { // Create 2 canonical queries, one with collation. auto qr = stdx::make_unique(nss); qr->setFilter(fromjson("{a: 'foo'}")); - auto statusWithCQ = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr cq = std::move(statusWithCQ.getValue()); auto qrCollation = stdx::make_unique(nss); qrCollation->setFilter(fromjson("{a: 'foo'}")); qrCollation->setCollation(fromjson("{locale: 'mock_reverse_string'}")); - auto statusWithCQCollation = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qrCollation), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQCollation = CanonicalQuery::canonicalize(opCtx.get(), std::move(qrCollation)); ASSERT_OK(statusWithCQCollation.getStatus()); unique_ptr cqCollation = std::move(statusWithCQCollation.getValue()); @@ -519,8 +512,7 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) { // Create a canonical query auto qr = stdx::make_unique(nss); qr->setFilter(fromjson("{a: 1}")); - auto statusWithCQ = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr cq = std::move(statusWithCQ.getValue()); @@ -547,8 +539,7 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionFalse) { // Create a canonical query auto qr = stdx::make_unique(nss); qr->setFilter(fromjson("{a: 1}")); - auto statusWithCQ = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr cq = std::move(statusWithCQ.getValue()); @@ -578,15 +569,13 @@ TEST(PlanCacheCommandsTest, planCacheListPlansCollation) { // Create 2 canonical queries, one with collation. auto qr = stdx::make_unique(nss); qr->setFilter(fromjson("{a: 'foo'}")); - auto statusWithCQ = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qr), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(qr)); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr cq = std::move(statusWithCQ.getValue()); auto qrCollation = stdx::make_unique(nss); qrCollation->setFilter(fromjson("{a: 'foo'}")); qrCollation->setCollation(fromjson("{locale: 'mock_reverse_string'}")); - auto statusWithCQCollation = CanonicalQuery::canonicalize( - opCtx.get(), std::move(qrCollation), ExtensionsCallbackDisallowExtensions()); + auto statusWithCQCollation = CanonicalQuery::canonicalize(opCtx.get(), std::move(qrCollation)); ASSERT_OK(statusWithCQCollation.getStatus()); unique_ptr cqCollation = std::move(statusWithCQCollation.getValue()); -- cgit v1.2.1