summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-04-26 15:06:23 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-04-27 13:19:24 -0400
commiteec194e751f6c36e53c241da3a1b42fd4b9b98a1 (patch)
tree6ba88aac4aba6ba218d1e92be5e84aa514fb1a69 /src
parent2df6ea3c5b70acc3927a08690f8d42b9d35b8709 (diff)
downloadmongo-eec194e751f6c36e53c241da3a1b42fd4b9b98a1.tar.gz
SERVER-28983 Fix undefined behaviour for the 'aggregate' command
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/pipeline_command.cpp11
-rw-r--r--src/mongo/db/pipeline/aggregation_request.cpp24
-rw-r--r--src/mongo/db/pipeline/aggregation_request.h24
-rw-r--r--src/mongo/s/commands/cluster_pipeline_cmd.cpp8
4 files changed, 29 insertions, 38 deletions
diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp
index af863000b60..fcfb1156b7f 100644
--- a/src/mongo/db/commands/pipeline_command.cpp
+++ b/src/mongo/db/commands/pipeline_command.cpp
@@ -28,7 +28,6 @@
#include "mongo/platform/basic.h"
-#include "mongo/base/init.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/client.h"
@@ -50,8 +49,7 @@ bool isMergePipeline(const std::vector<BSONObj>& pipeline) {
class PipelineCommand : public Command {
public:
- PipelineCommand()
- : Command(AggregationRequest::kCommandName) {} // command is called "aggregate"
+ PipelineCommand() : Command("aggregate", false) {}
// Locks are managed manually, in particular by DocumentSourceCursor.
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -152,13 +150,8 @@ public:
return runAggregate(opCtx, nss, request.getValue(), cmdObj, *out);
}
-};
-MONGO_INITIALIZER(PipelineCommand)(InitializerContext* context) {
- new PipelineCommand();
-
- return Status::OK();
-}
+} pipelineCmd;
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/pipeline/aggregation_request.cpp b/src/mongo/db/pipeline/aggregation_request.cpp
index 163c4f288c1..f915ab47431 100644
--- a/src/mongo/db/pipeline/aggregation_request.cpp
+++ b/src/mongo/db/pipeline/aggregation_request.cpp
@@ -47,18 +47,18 @@
namespace mongo {
-const StringData AggregationRequest::kCommandName = "aggregate"_sd;
-const StringData AggregationRequest::kCursorName = "cursor"_sd;
-const StringData AggregationRequest::kBatchSizeName = "batchSize"_sd;
-const StringData AggregationRequest::kFromRouterName = "fromRouter"_sd;
-const StringData AggregationRequest::kPipelineName = "pipeline"_sd;
-const StringData AggregationRequest::kCollationName = "collation"_sd;
-const StringData AggregationRequest::kExplainName = "explain"_sd;
-const StringData AggregationRequest::kAllowDiskUseName = "allowDiskUse"_sd;
-const StringData AggregationRequest::kHintName = "hint"_sd;
-const StringData AggregationRequest::kCommentName = "comment"_sd;
-
-const long long AggregationRequest::kDefaultBatchSize = 101;
+constexpr StringData AggregationRequest::kCommandName;
+constexpr StringData AggregationRequest::kCursorName;
+constexpr StringData AggregationRequest::kBatchSizeName;
+constexpr StringData AggregationRequest::kFromRouterName;
+constexpr StringData AggregationRequest::kPipelineName;
+constexpr StringData AggregationRequest::kCollationName;
+constexpr StringData AggregationRequest::kExplainName;
+constexpr StringData AggregationRequest::kAllowDiskUseName;
+constexpr StringData AggregationRequest::kHintName;
+constexpr StringData AggregationRequest::kCommentName;
+
+constexpr long long AggregationRequest::kDefaultBatchSize;
AggregationRequest::AggregationRequest(NamespaceString nss, std::vector<BSONObj> pipeline)
: _nss(std::move(nss)), _pipeline(std::move(pipeline)), _batchSize(kDefaultBatchSize) {}
diff --git a/src/mongo/db/pipeline/aggregation_request.h b/src/mongo/db/pipeline/aggregation_request.h
index 1f290f26a90..14b4dad0e59 100644
--- a/src/mongo/db/pipeline/aggregation_request.h
+++ b/src/mongo/db/pipeline/aggregation_request.h
@@ -47,18 +47,18 @@ class Document;
*/
class AggregationRequest {
public:
- static const StringData kCommandName;
- static const StringData kCursorName;
- static const StringData kBatchSizeName;
- static const StringData kFromRouterName;
- static const StringData kPipelineName;
- static const StringData kCollationName;
- static const StringData kExplainName;
- static const StringData kAllowDiskUseName;
- static const StringData kHintName;
- static const StringData kCommentName;
-
- static const long long kDefaultBatchSize;
+ static constexpr StringData kCommandName = "aggregate"_sd;
+ static constexpr StringData kCursorName = "cursor"_sd;
+ static constexpr StringData kBatchSizeName = "batchSize"_sd;
+ static constexpr StringData kFromRouterName = "fromRouter"_sd;
+ static constexpr StringData kPipelineName = "pipeline"_sd;
+ static constexpr StringData kCollationName = "collation"_sd;
+ static constexpr StringData kExplainName = "explain"_sd;
+ static constexpr StringData kAllowDiskUseName = "allowDiskUse"_sd;
+ static constexpr StringData kHintName = "hint"_sd;
+ static constexpr StringData kCommentName = "comment"_sd;
+
+ static constexpr long long kDefaultBatchSize = 101;
/**
* Create a new instance of AggregationRequest by parsing the raw command object. Returns a
diff --git a/src/mongo/s/commands/cluster_pipeline_cmd.cpp b/src/mongo/s/commands/cluster_pipeline_cmd.cpp
index 4f4431b52ec..ffdf5f2ffde 100644
--- a/src/mongo/s/commands/cluster_pipeline_cmd.cpp
+++ b/src/mongo/s/commands/cluster_pipeline_cmd.cpp
@@ -41,12 +41,9 @@
namespace mongo {
namespace {
-/**
- * Implements the aggregation (pipeline command for sharding).
- */
-class PipelineCommand : public Command {
+class ClusterPipelineCommand : public Command {
public:
- PipelineCommand() : Command(AggregationRequest::kCommandName, false) {}
+ ClusterPipelineCommand() : Command("aggregate", false) {}
virtual bool slaveOk() const {
return true;
@@ -124,6 +121,7 @@ public:
return ClusterAggregate::runAggregate(opCtx, nsStruct, request.getValue(), aggCmd, out);
}
+
} clusterPipelineCmd;
} // namespace