diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2015-11-06 11:46:05 -0500 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2015-11-10 15:21:44 -0500 |
commit | e001158d2da317ae36030cf4919ab8ebb9bdf8b2 (patch) | |
tree | 90c7ba512ee748caf911f2cfe885cba995dfc1f6 /src/mongo/bson | |
parent | 47f20b624ea81232b9c30d69f1b4f982891494dc (diff) | |
download | mongo-e001158d2da317ae36030cf4919ab8ebb9bdf8b2.tar.gz |
SERVER-20609 make BSON validation inlineable
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsonobj.cpp | 44 | ||||
-rw-r--r-- | src/mongo/bson/bsonobj.h | 20 |
2 files changed, 15 insertions, 49 deletions
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp index 2cd2ef64bde..d1fd73ad43c 100644 --- a/src/mongo/bson/bsonobj.cpp +++ b/src/mongo/bson/bsonobj.cpp @@ -791,50 +791,6 @@ void BSONObj::toString(StringBuilder& s, bool isArray, bool full, int depth) con s << (isArray ? " ]" : " }"); } -Status DataType::Handler<BSONObj>::load( - BSONObj* bson, const char* ptr, size_t length, size_t* advanced, std::ptrdiff_t debug_offset) { - auto len = ConstDataRange(ptr, ptr + length).read<LittleEndian<uint32_t>>(); - - if (!len.isOK()) { - mongoutils::str::stream ss; - ss << "buffer size too small to read length at offset: " << debug_offset; - return Status(ErrorCodes::InvalidBSON, ss); - } - - if (len.getValue() > length) { - mongoutils::str::stream ss; - ss << "length (" << len.getValue() << ") greater than buffer size (" << length - << ") at offset: " << debug_offset; - return Status(ErrorCodes::InvalidBSON, ss); - } - - if (len.getValue() < BSONObj::kMinBSONLength) { - mongoutils::str::stream ss; - ss << "Invalid bson length (" << len.getValue() << ") at offset: " << debug_offset; - return Status(ErrorCodes::InvalidBSON, ss); - } - - try { - BSONObj temp(ptr); - - if (bson) { - *bson = std::move(temp); - } - } catch (...) { - auto status = exceptionToStatus(); - mongoutils::str::stream ss; - ss << status.reason() << " at offset: " << debug_offset; - - return Status(status.code(), ss); - } - - if (advanced) { - *advanced = len.getValue(); - } - - return Status::OK(); -} - Status DataType::Handler<BSONObj>::store( const BSONObj& bson, char* ptr, size_t length, size_t* advanced, std::ptrdiff_t debug_offset) { if (bson.objsize() > static_cast<int>(length)) { diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h index dd19526d47a..56785df3a62 100644 --- a/src/mongo/bson/bsonobj.h +++ b/src/mongo/bson/bsonobj.h @@ -36,13 +36,13 @@ #include <utility> #include <vector> -#include "mongo/bson/timestamp.h" -#include "mongo/bson/bsontypes.h" -#include "mongo/bson/oid.h" -#include "mongo/bson/bsonelement.h" #include "mongo/base/data_type.h" #include "mongo/base/disallow_copying.h" #include "mongo/base/string_data.h" +#include "mongo/bson/bsonelement.h" +#include "mongo/bson/bsontypes.h" +#include "mongo/bson/oid.h" +#include "mongo/bson/timestamp.h" #include "mongo/bson/util/builder.h" #include "mongo/platform/atomic_word.h" #include "mongo/util/bufreader.h" @@ -801,7 +801,17 @@ struct DataType::Handler<BSONObj> { const char* ptr, size_t length, size_t* advanced, - std::ptrdiff_t debug_offset); + std::ptrdiff_t debug_offset) { + auto temp = BSONObj(ptr); + auto len = temp.objsize(); + if (bson) { + *bson = std::move(temp); + } + if (advanced) { + *advanced = len; + } + return Status::OK(); + } static Status store(const BSONObj& bson, char* ptr, |