summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bson_validate.cpp
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2016-04-22 10:58:55 -0400
committerGeert Bosch <geert@mongodb.com>2016-04-22 14:58:59 -0400
commit1a61f2e56e33da64cbf64090584e8da900f09241 (patch)
tree149b5cf6963c6ca7c040ebb6a261cf648ddba30d /src/mongo/bson/bson_validate.cpp
parenta0cc23b3068d8ef6f596241187258515bbc59187 (diff)
downloadmongo-1a61f2e56e33da64cbf64090584e8da900f09241.tar.gz
SERVER-1393 Allow specifying BSON version to validate
Diffstat (limited to 'src/mongo/bson/bson_validate.cpp')
-rw-r--r--src/mongo/bson/bson_validate.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/mongo/bson/bson_validate.cpp b/src/mongo/bson/bson_validate.cpp
index 9ef873eb47a..b3ceab482cf 100644
--- a/src/mongo/bson/bson_validate.cpp
+++ b/src/mongo/bson/bson_validate.cpp
@@ -35,6 +35,7 @@
#include "mongo/bson/bson_validate.h"
#include "mongo/bson/oid.h"
#include "mongo/db/jsobj.h"
+#include "mongo/db/server_parameters.h"
#include "mongo/platform/decimal128.h"
namespace mongo {
@@ -56,8 +57,8 @@ Status makeError(std::string baseMsg, BSONElement idElem) {
class Buffer {
public:
- Buffer(const char* buffer, uint64_t maxLength)
- : _buffer(buffer), _position(0), _maxLength(maxLength) {}
+ Buffer(const char* buffer, uint64_t maxLength, BSONVersion version)
+ : _buffer(buffer), _position(0), _maxLength(maxLength), _version(version) {}
template <typename N>
bool readNumber(N* out) {
@@ -125,6 +126,10 @@ public:
return _buffer;
}
+ BSONVersion version() const {
+ return _version;
+ }
+
/**
* WARNING: only pass in a non-EOO idElem if it has been fully validated already!
*/
@@ -137,6 +142,7 @@ private:
uint64_t _position;
uint64_t _maxLength;
BSONElement _idElem;
+ BSONVersion _version;
};
struct ValidationState {
@@ -223,14 +229,14 @@ Status validateElementInfo(Buffer* buffer, ValidationState::State* nextState, BS
return Status::OK();
case NumberDecimal:
- if (Decimal128::enabled) {
+ if (Decimal128::enabled && buffer->version() != BSONVersion::kV1_0) {
if (!buffer->skip(sizeof(Decimal128::Value)))
return makeError("Invalid bson", idElem);
return Status::OK();
} else {
- return Status(ErrorCodes::InvalidBSON,
- "Attempt to use a decimal BSON type when experimental decimal "
- "server support is not currently enabled.");
+ return Status(
+ ErrorCodes::InvalidBSON,
+ "Attempt to use a decimal BSON type when support is not currently enabled.");
}
case DBRef:
@@ -380,12 +386,12 @@ Status validateBSONIterative(Buffer* buffer) {
} // namespace
-Status validateBSON(const char* originalBuffer, uint64_t maxLength) {
+Status validateBSON(const char* originalBuffer, uint64_t maxLength, BSONVersion version) {
if (maxLength < 5) {
return Status(ErrorCodes::InvalidBSON, "bson data has to be at least 5 bytes");
}
- Buffer buf(originalBuffer, maxLength);
+ Buffer buf(originalBuffer, maxLength, version);
return validateBSONIterative(&buf);
}