summaryrefslogtreecommitdiff
path: root/src/mongo/db/write_concern_options.cpp
diff options
context:
space:
mode:
authorAmirsaman Memaripour <amirsaman.memaripour@10gen.com>2020-02-03 23:15:40 +0000
committerevergreen <evergreen@mongodb.com>2020-02-03 23:15:40 +0000
commit6527449a3c0d0acba0ace9c421fd0580b4afbffa (patch)
tree47fda59e385b1e7430b94f52a44dc8f31b6422c3 /src/mongo/db/write_concern_options.cpp
parent860b5fdf681581e211d3be50bfc67007c81530a9 (diff)
downloadmongo-6527449a3c0d0acba0ace9c421fd0580b4afbffa.tar.gz
SERVER-45920 Validate writeConcern.w
Diffstat (limited to 'src/mongo/db/write_concern_options.cpp')
-rw-r--r--src/mongo/db/write_concern_options.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mongo/db/write_concern_options.cpp b/src/mongo/db/write_concern_options.cpp
index 80e1c8bd0e4..f24ec703469 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,14 @@ StatusWith<WriteConcernOptions> WriteConcernOptions::parse(const BSONObj& obj) {
}
if (wEl.isNumber()) {
- writeConcern.wNumNodes = wEl.numberInt();
+ auto wNumNodes = wEl.safeNumberLong();
+ if (wNumNodes < 0 ||
+ wNumNodes > static_cast<decltype(wNumNodes)>(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<decltype(writeConcern.wNumNodes)>(wNumNodes);
writeConcern.usedDefaultW = false;
} else if (wEl.type() == String) {
writeConcern.wNumNodes = 0;