diff options
author | Amirsaman Memaripour <amirsaman.memaripour@10gen.com> | 2020-01-28 21:03:01 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-28 21:03:01 +0000 |
commit | 8a4dba3b0c26e7649c9da3ce05799782682aa1dc (patch) | |
tree | 7f901b5c2879ffa359e5d0c48fe68f2130978f41 /src/mongo/db/write_concern_options.cpp | |
parent | 16a897ece7ffe8f1d2ae7216ff640fa9ef96edd0 (diff) | |
download | mongo-8a4dba3b0c26e7649c9da3ce05799782682aa1dc.tar.gz |
SERVER-45584 Validate writeConcern.w
Diffstat (limited to 'src/mongo/db/write_concern_options.cpp')
-rw-r--r-- | src/mongo/db/write_concern_options.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/mongo/db/write_concern_options.cpp b/src/mongo/db/write_concern_options.cpp index 80e1c8bd0e4..3cf49672de2 100644 --- a/src/mongo/db/write_concern_options.cpp +++ b/src/mongo/db/write_concern_options.cpp @@ -35,6 +35,7 @@ #include "mongo/base/string_data.h" #include "mongo/bson/util/bson_extract.h" #include "mongo/db/field_parser.h" +#include "mongo/db/repl/repl_set_config.h" #include "mongo/util/str.h" namespace mongo { @@ -151,7 +152,13 @@ StatusWith<WriteConcernOptions> WriteConcernOptions::parse(const BSONObj& obj) { } if (wEl.isNumber()) { - writeConcern.wNumNodes = wEl.numberInt(); + auto wNumNodes = wEl.safeNumberLong(); + if (wNumNodes < 0 || wNumNodes > static_cast<long long>(repl::ReplSetConfig::kMaxMembers)) { + return Status(ErrorCodes::FailedToParse, + str::stream() << "w has to be a non-negative number and not greater than " + << repl::ReplSetConfig::kMaxMembers); + } + writeConcern.wNumNodes = static_cast<int>(wNumNodes); writeConcern.usedDefaultW = false; } else if (wEl.type() == String) { writeConcern.wNumNodes = 0; |