summaryrefslogtreecommitdiff
path: root/src/mongo/db/write_concern_options.cpp
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-03-12 13:40:45 -0400
committerGreg Studer <greg@10gen.com>2014-03-12 14:42:32 -0400
commiteadeef174f9e7df1a94c7db06b80277fb60efd25 (patch)
treee1cff4e21bc71430b89cf718e1b3cd52a72be9fb /src/mongo/db/write_concern_options.cpp
parent9bea47352928c4734e2e12318694d2389052e055 (diff)
downloadmongo-eadeef174f9e7df1a94c7db06b80277fb60efd25.tar.gz
SERVER-12978 more validation of write concern options
Diffstat (limited to 'src/mongo/db/write_concern_options.cpp')
-rw-r--r--src/mongo/db/write_concern_options.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/mongo/db/write_concern_options.cpp b/src/mongo/db/write_concern_options.cpp
index db18073a3ac..848c4e4464c 100644
--- a/src/mongo/db/write_concern_options.cpp
+++ b/src/mongo/db/write_concern_options.cpp
@@ -38,14 +38,26 @@ namespace mongo {
Status WriteConcernOptions::parse( const BSONObj& obj ) {
if ( obj.isEmpty() ) {
- return Status( ErrorCodes::BadValue, "write concern object cannot be empty" );
+ return Status( ErrorCodes::FailedToParse, "write concern object cannot be empty" );
}
- bool j = obj["j"].trueValue();
- bool fsync = obj["fsync"].trueValue();
+ BSONElement jEl = obj["j"];
+ if ( !jEl.eoo() && !jEl.isNumber() && jEl.type() != Bool ) {
+ return Status( ErrorCodes::FailedToParse, "j must be numeric or a boolean value" );
+ }
+
+ const bool j = jEl.trueValue();
+
+ BSONElement fsyncEl = obj["fsync"];
+ if ( !fsyncEl.eoo() && !fsyncEl.isNumber() && fsyncEl.type() != Bool ) {
+ return Status( ErrorCodes::FailedToParse, "fsync must be numeric or a boolean value" );
+ }
+
+ const bool fsync = fsyncEl.trueValue();
- if ( j & fsync )
- return Status( ErrorCodes::BadValue, "fsync and j options cannot be used together" );
+ if ( j && fsync )
+ return Status( ErrorCodes::FailedToParse,
+ "fsync and j options cannot be used together" );
if ( j ) {
syncMode = JOURNAL;
@@ -67,7 +79,7 @@ namespace mongo {
wNumNodes = 1;
}
else {
- return Status( ErrorCodes::BadValue, "w has to be a number or a string" );
+ return Status( ErrorCodes::FailedToParse, "w has to be a number or a string" );
}
wTimeout = obj["wtimeout"].numberInt();