diff options
Diffstat (limited to 'src')
28 files changed, 82 insertions, 109 deletions
diff --git a/src/mongo/bson/bson_validate.cpp b/src/mongo/bson/bson_validate.cpp index 3a7a9bf728e..0cde1abe151 100644 --- a/src/mongo/bson/bson_validate.cpp +++ b/src/mongo/bson/bson_validate.cpp @@ -70,8 +70,8 @@ MONGO_COMPILER_NOINLINE Status makeError(StringData baseMsg, class Buffer { public: - Buffer(const char* buffer, uint64_t maxLength, BSONVersion version) - : _buffer(buffer), _position(0), _maxLength(maxLength), _version(version) {} + Buffer(const char* buffer, uint64_t maxLength) + : _buffer(buffer), _position(0), _maxLength(maxLength) {} template <typename N> bool readNumber(N* out) { @@ -149,10 +149,6 @@ public: return _buffer; } - BSONVersion version() const { - return _version; - } - /** * WARNING: only pass in a non-EOO idElem if it has been fully validated already! */ @@ -165,7 +161,6 @@ private: uint64_t _position; uint64_t _maxLength; BSONElement _idElem; - BSONVersion _version; }; struct ValidationState { @@ -417,12 +412,12 @@ Status validateBSONIterative(Buffer* buffer) { } // namespace -Status validateBSON(const char* originalBuffer, uint64_t maxLength, BSONVersion version) { +Status validateBSON(const char* originalBuffer, uint64_t maxLength) { if (maxLength < 5) { return Status(ErrorCodes::InvalidBSON, "bson data has to be at least 5 bytes"); } - Buffer buf(originalBuffer, maxLength, version); + Buffer buf(originalBuffer, maxLength); return validateBSONIterative(&buf); } diff --git a/src/mongo/bson/bson_validate.h b/src/mongo/bson/bson_validate.h index 13892ff80ab..4644ab361c4 100644 --- a/src/mongo/bson/bson_validate.h +++ b/src/mongo/bson/bson_validate.h @@ -42,8 +42,7 @@ class Status; * @param buf - bson data * @param maxLength - maxLength of buffer * this is NOT the bson size, but how far we know the buffer is valid - * @param version - newest version to accept */ -Status validateBSON(const char* buf, uint64_t maxLength, BSONVersion version); +Status validateBSON(const char* buf, uint64_t maxLength); } // namespace mongo diff --git a/src/mongo/bson/bson_validate_fuzzer.cpp b/src/mongo/bson/bson_validate_fuzzer.cpp index 074c7b1682b..9ee05dbf29a 100644 --- a/src/mongo/bson/bson_validate_fuzzer.cpp +++ b/src/mongo/bson/bson_validate_fuzzer.cpp @@ -30,6 +30,6 @@ #include "mongo/bson/bson_validate.h" extern "C" int LLVMFuzzerTestOneInput(const char* Data, size_t Size) { - mongo::Status ret = mongo::validateBSON(Data, Size, mongo::BSONVersion::kLatest); + mongo::Status ret = mongo::validateBSON(Data, Size); return 0; } diff --git a/src/mongo/bson/bson_validate_test.cpp b/src/mongo/bson/bson_validate_test.cpp index a07ae0b928d..a7fede6dada 100644 --- a/src/mongo/bson/bson_validate_test.cpp +++ b/src/mongo/bson/bson_validate_test.cpp @@ -54,10 +54,10 @@ void appendInvalidStringElement(const char* fieldName, BufBuilder* bb) { TEST(BSONValidate, Basic) { BSONObj x; - ASSERT_TRUE(x.valid(BSONVersion::kLatest)); + ASSERT_TRUE(x.valid()); x = BSON("x" << 1); - ASSERT_TRUE(x.valid(BSONVersion::kLatest)); + ASSERT_TRUE(x.valid()); } TEST(BSONValidate, RandomData) { @@ -83,12 +83,12 @@ TEST(BSONValidate, RandomData) { ASSERT_EQUALS(size, o.objsize()); - if (o.valid(BSONVersion::kLatest)) { + if (o.valid()) { numValid++; jsonSize += o.jsonString().size(); - ASSERT_OK(validateBSON(o.objdata(), o.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(o.objdata(), o.objsize())); } else { - ASSERT_NOT_OK(validateBSON(o.objdata(), o.objsize(), BSONVersion::kLatest)); + ASSERT_NOT_OK(validateBSON(o.objdata(), o.objsize())); } delete[] x; @@ -134,12 +134,12 @@ TEST(BSONValidate, MuckingData1) { data[i] = 0xc8U; numToRun++; - if (mine.valid(BSONVersion::kLatest)) { + if (mine.valid()) { numValid++; jsonSize += mine.jsonString().size(); - ASSERT_OK(validateBSON(mine.objdata(), mine.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(mine.objdata(), mine.objsize())); } else { - ASSERT_NOT_OK(validateBSON(mine.objdata(), mine.objsize(), BSONVersion::kLatest)); + ASSERT_NOT_OK(validateBSON(mine.objdata(), mine.objsize())); } } @@ -191,29 +191,29 @@ TEST(BSONValidate, Fuzz) { // to compare outputs against (BSONObj::valid() is a wrapper for validateBSON()). // Thus, the reason for this test is to ensure that validateBSON() doesn't trip // any ASAN or UBSAN check when fed fuzzed input. - validateBSON(fuzzed.objdata(), fuzzed.objsize(), BSONVersion::kLatest).isOK(); + validateBSON(fuzzed.objdata(), fuzzed.objsize()).isOK(); } } TEST(BSONValidateFast, Empty) { BSONObj x; - ASSERT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(x.objdata(), x.objsize())); } TEST(BSONValidateFast, RegEx) { BSONObjBuilder b; b.appendRegex("foo", "i"); BSONObj x = b.obj(); - ASSERT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(x.objdata(), x.objsize())); } TEST(BSONValidateFast, Simple0) { BSONObj x; - ASSERT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(x.objdata(), x.objsize())); x = BSON("foo" << 17 << "bar" << "eliot"); - ASSERT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(x.objdata(), x.objsize())); } TEST(BSONValidateFast, Simple2) { @@ -225,7 +225,7 @@ TEST(BSONValidateFast, Simple2) { sprintf(buf, "bar%d", i); b.appendMaxForType(buf, i); BSONObj x = b.obj(); - ASSERT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(x.objdata(), x.objsize())); } } @@ -240,15 +240,15 @@ TEST(BSONValidateFast, Simple3) { b.appendMaxForType(buf, i); } BSONObj x = b.obj(); - ASSERT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(x.objdata(), x.objsize())); } TEST(BSONValidateFast, NestedObject) { BSONObj x = BSON("a" << 1 << "b" << BSON("c" << 2 << "d" << BSONArrayBuilder().obj() << "e" << BSON_ARRAY("1" << 2 << 3))); - ASSERT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); - ASSERT_NOT_OK(validateBSON(x.objdata(), x.objsize() / 2, BSONVersion::kLatest)); + ASSERT_OK(validateBSON(x.objdata(), x.objsize())); + ASSERT_NOT_OK(validateBSON(x.objdata(), x.objsize() / 2)); } TEST(BSONValidateFast, ErrorWithId) { @@ -257,7 +257,7 @@ TEST(BSONValidateFast, ErrorWithId) { ob.append("_id", 1); appendInvalidStringElement("not_id", &bb); const BSONObj x = ob.done(); - const Status status = validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest); + const Status status = validateBSON(x.objdata(), x.objsize()); ASSERT_NOT_OK(status); ASSERT_EQUALS( status.reason(), @@ -270,7 +270,7 @@ TEST(BSONValidateFast, ErrorBeforeId) { appendInvalidStringElement("not_id", &bb); ob.append("_id", 1); const BSONObj x = ob.done(); - const Status status = validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest); + const Status status = validateBSON(x.objdata(), x.objsize()); ASSERT_NOT_OK(status); ASSERT_EQUALS(status.reason(), "not null terminated string in element with field name 'not_id' in object with " @@ -282,7 +282,7 @@ TEST(BSONValidateFast, ErrorNoId) { BSONObjBuilder ob(bb); appendInvalidStringElement("not_id", &bb); const BSONObj x = ob.done(); - const Status status = validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest); + const Status status = validateBSON(x.objdata(), x.objsize()); ASSERT_NOT_OK(status); ASSERT_EQUALS(status.reason(), "not null terminated string in element with field name 'not_id' in object with " @@ -294,7 +294,7 @@ TEST(BSONValidateFast, ErrorIsInId) { BSONObjBuilder ob(bb); appendInvalidStringElement("_id", &bb); const BSONObj x = ob.done(); - const Status status = validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest); + const Status status = validateBSON(x.objdata(), x.objsize()); ASSERT_NOT_OK(status); ASSERT_EQUALS( status.reason(), @@ -309,7 +309,7 @@ TEST(BSONValidateFast, NonTopLevelId) { << "not the real _id")); appendInvalidStringElement("not_id2", &bb); const BSONObj x = ob.done(); - const Status status = validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest); + const Status status = validateBSON(x.objdata(), x.objsize()); ASSERT_NOT_OK(status); ASSERT_EQUALS(status.reason(), "not null terminated string in element with field name 'not_id2' in object with " @@ -329,14 +329,14 @@ TEST(BSONValidateFast, StringHasSomething) { + 4 // size , x.objsize()); - ASSERT_NOT_OK(validateBSON(x.objdata(), x.objsize(), BSONVersion::kLatest)); + ASSERT_NOT_OK(validateBSON(x.objdata(), x.objsize())); } TEST(BSONValidateBool, BoolValuesAreValidated) { BSONObjBuilder bob; bob.append("x", false); const BSONObj obj = bob.done(); - ASSERT_OK(validateBSON(obj.objdata(), obj.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(obj.objdata(), obj.objsize())); const BSONElement x = obj["x"]; // Legal, because we know that the BufBuilder gave // us back some heap memory, which isn't oringinally const. @@ -346,9 +346,9 @@ TEST(BSONValidateBool, BoolValuesAreValidated) { ++val) { *writable = static_cast<char>(val); if ((val == 0) || (val == 1)) { - ASSERT_OK(validateBSON(obj.objdata(), obj.objsize(), BSONVersion::kLatest)); + ASSERT_OK(validateBSON(obj.objdata(), obj.objsize())); } else { - ASSERT_NOT_OK(validateBSON(obj.objdata(), obj.objsize(), BSONVersion::kLatest)); + ASSERT_NOT_OK(validateBSON(obj.objdata(), obj.objsize())); } } } @@ -361,7 +361,7 @@ TEST(BSONValidateFast, InvalidType) { BSONObj obj(buffer); // Validate fails. - ASSERT_NOT_OK(validateBSON(obj.objdata(), obj.objsize(), BSONVersion::kLatest)); + ASSERT_NOT_OK(validateBSON(obj.objdata(), obj.objsize())); ASSERT_THROWS_CODE(obj.woCompare(BSON("A" << 1)), DBException, 10320); } diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp index 4c5f2982ae0..27963db4611 100644 --- a/src/mongo/bson/bsonobj.cpp +++ b/src/mongo/bson/bsonobj.cpp @@ -264,8 +264,8 @@ BSONObj BSONObj::jsonStringBuffer(JsonStringFormat format, } } -bool BSONObj::valid(BSONVersion version) const { - return validateBSON(objdata(), objsize(), version).isOK(); +bool BSONObj::valid() const { + return validateBSON(objdata(), objsize()).isOK(); } int BSONObj::woCompare(const BSONObj& r, diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h index d8021e9f529..12374110747 100644 --- a/src/mongo/bson/bsonobj.h +++ b/src/mongo/bson/bsonobj.h @@ -576,10 +576,9 @@ public: bool hasFieldNames() const; /** - * Returns true if this object is valid according to the specified BSON version, and returns - * false otherwise. + * Returns true if this object is valid and returns false otherwise. */ - bool valid(BSONVersion version) const; + bool valid() const; /** add all elements of the object to the specified vector */ void elems(std::vector<BSONElement>&) const; diff --git a/src/mongo/bson/bsontypes.h b/src/mongo/bson/bsontypes.h index b2b5b7399e8..50588789dcc 100644 --- a/src/mongo/bson/bsontypes.h +++ b/src/mongo/bson/bsontypes.h @@ -56,11 +56,6 @@ extern const BSONObj kMaxBSONKey; extern const BSONObj kMinBSONKey; /** - determines BSON types considered valid by validate -*/ -enum class BSONVersion { kV1_0, kV1_1, kLatest = kV1_1 }; - -/** the complete list of valid BSON types see also bsonspec.org */ diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp index c141bb04b5c..7e83de38bc0 100644 --- a/src/mongo/client/dbclient_cursor.cpp +++ b/src/mongo/client/dbclient_cursor.cpp @@ -583,7 +583,6 @@ DBClientCursor::DBClientCursor(DBClientBase* client, cursorId(cursorId), _ownCursor(true), wasError(false), - _enabledBSONVersion(Validator<BSONObj>::enabledBSONVersion()), _readConcernObj(readConcernObj) { if (queryOptions & QueryOptionLocal_forceOpQuery) { // Legacy OP_QUERY does not support UUIDs. diff --git a/src/mongo/client/dbclient_cursor.h b/src/mongo/client/dbclient_cursor.h index 33fb9f2e3c9..cbc73341f88 100644 --- a/src/mongo/client/dbclient_cursor.h +++ b/src/mongo/client/dbclient_cursor.h @@ -301,7 +301,6 @@ private: std::string _scopedHost; std::string _lazyHost; bool wasError; - BSONVersion _enabledBSONVersion; bool _useFindCommand = true; bool _connectionHasPendingReplies = false; int _lastRequestId = 0; diff --git a/src/mongo/client/mongo_uri_test.cpp b/src/mongo/client/mongo_uri_test.cpp index d53ca990602..b7f1df41482 100644 --- a/src/mongo/client/mongo_uri_test.cpp +++ b/src/mongo/client/mongo_uri_test.cpp @@ -582,7 +582,7 @@ BSONObj getBsonFromJsonFile(std::string fileName) { std::ifstream infile(filename.c_str()); std::string data((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>()); BSONObj obj = fromjson(data); - ASSERT_TRUE(obj.valid(BSONVersion::kLatest)); + ASSERT_TRUE(obj.valid()); ASSERT_TRUE(obj.hasField("tests")); BSONObj arr = obj.getField("tests").embeddedObject().getOwned(); ASSERT_TRUE(arr.couldBeArray()); diff --git a/src/mongo/db/catalog/index_build_entry_test.cpp b/src/mongo/db/catalog/index_build_entry_test.cpp index 7daf4400d46..ffa6a870874 100644 --- a/src/mongo/db/catalog/index_build_entry_test.cpp +++ b/src/mongo/db/catalog/index_build_entry_test.cpp @@ -124,7 +124,7 @@ TEST(IndexBuildEntryTest, SerializeAndDeserialize) { entry.setCommitReadyMembers(generateCommitReadyMembers(3)); BSONObj obj = entry.toBSON(); - ASSERT_TRUE(obj.valid(BSONVersion::kLatest)); + ASSERT_TRUE(obj.valid()); IDLParserErrorContext ctx("IndexBuildsEntry Parser"); IndexBuildEntry rebuiltEntry = IndexBuildEntry::parse(ctx, obj); diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index f507d30f85d..d6e379bce7f 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -160,9 +160,8 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd for (int i = 0; record && i < internalInsertMaxBatchSize.load(); i++) { RecordId id = record->id; RecordData& data = record->data; - // Use the latest BSON validation version. We retain decimal data when repairing - // database even if decimal is disabled. - auto validStatus = validateBSON(data.data(), data.size(), BSONVersion::kLatest); + // We retain decimal data when repairing database even if decimal is disabled. + auto validStatus = validateBSON(data.data(), data.size()); if (!validStatus.isOK()) { if (repair == RepairData::kNo) { LOGV2_FATAL(31396, diff --git a/src/mongo/db/catalog/validate_adaptor.cpp b/src/mongo/db/catalog/validate_adaptor.cpp index 5ac5b244f53..c4c2779ea88 100644 --- a/src/mongo/db/catalog/validate_adaptor.cpp +++ b/src/mongo/db/catalog/validate_adaptor.cpp @@ -78,8 +78,7 @@ Status ValidateAdaptor::validateRecord(OperationContext* opCtx, LOGV2(46666001, "[validate]", "recordId"_attr = recordId, "recordData"_attr = recordBson); } - const Status status = validateBSON( - recordBson.objdata(), recordBson.objsize(), Validator<BSONObj>::enabledBSONVersion()); + const Status status = validateBSON(recordBson.objdata(), recordBson.objsize()); if (status.isOK()) { *dataSize = recordBson.objsize(); } else { diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 446fcd1a088..19f1e8efd41 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -162,9 +162,8 @@ struct Cloner::Fun { BSONObj tmp = i.nextSafe(); /* assure object is valid. note this will slow us down a little. */ - // Use the latest BSON validation version. We allow cloning of collections containing - // decimal data even if decimal is disabled. - const Status status = validateBSON(tmp.objdata(), tmp.objsize(), BSONVersion::kLatest); + // We allow cloning of collections containing decimal data even if decimal is disabled. + const Status status = validateBSON(tmp.objdata(), tmp.objsize()); if (!status.isOK()) { if (gSkipCorruptDocumentsWhenCloning.load()) { LOGV2_WARNING(20423, diff --git a/src/mongo/db/dbmessage.cpp b/src/mongo/db/dbmessage.cpp index e7b63168e46..0cd059e52e9 100644 --- a/src/mongo/db/dbmessage.cpp +++ b/src/mongo/db/dbmessage.cpp @@ -92,8 +92,7 @@ BSONObj DbMessage::nextJsObj() { _nextjsobj != nullptr && _theEnd - _nextjsobj >= 5); if (serverGlobalParams.objcheck) { - Status status = validateBSON( - _nextjsobj, _theEnd - _nextjsobj, Validator<BSONObj>::enabledBSONVersion()); + Status status = validateBSON(_nextjsobj, _theEnd - _nextjsobj); uassert(ErrorCodes::InvalidBSON, str::stream() << "Client Error: bad object in message: " << status.reason(), status.isOK()); diff --git a/src/mongo/db/lasterror.cpp b/src/mongo/db/lasterror.cpp index 1d919a14495..040bd399697 100644 --- a/src/mongo/db/lasterror.cpp +++ b/src/mongo/db/lasterror.cpp @@ -77,9 +77,8 @@ void LastError::recordUpdate(bool updateObjects, long long nObjects, BSONObj ups _nObjects = nObjects; _updatedExisting = updateObjects ? True : False; - // Use the latest BSON validation version. We record updates containing decimal data even if - // decimal is disabled. - if (upsertedId.valid(BSONVersion::kLatest) && upsertedId.hasField(kUpsertedFieldName)) + // We record updates containing decimal data even if decimal is disabled. + if (upsertedId.valid() && upsertedId.hasField(kUpsertedFieldName)) _upsertedId = upsertedId; } diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 7f558fe2a3f..20c80bc7d83 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -131,7 +131,7 @@ void generateLegacyQueryErrorResponse(const AssertionException& exception, Message* response) { curop->debug().errInfo = exception.toStatus(); - if (queryMessage.query.valid(BSONVersion::kLatest)) + if (queryMessage.query.valid()) LOGV2_OPTIONS(51777, {logv2::LogComponent::kQuery}, "Assertion {error} ns: {namespace} query: {query}", diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index 7e0f802c164..831ac4f41fe 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -284,8 +284,7 @@ TEST_F(KeyStringBuilderTest, ExceededBSONDepth) { nestedObj = BSON("" << nestedObj); } // This BSON object should not be valid. - auto validateStatus = - validateBSON(nestedObj.objdata(), nestedObj.objsize(), BSONVersion::kV1_1); + auto validateStatus = validateBSON(nestedObj.objdata(), nestedObj.objsize()); ASSERT_EQ(ErrorCodes::Overflow, validateStatus.code()); // Construct a KeyString from the invalid BSON, and confirm that it fails to convert back to diff --git a/src/mongo/db/storage/key_string_to_bson_fuzzer.cpp b/src/mongo/db/storage/key_string_to_bson_fuzzer.cpp index 8ec66a5c14b..3ed29c66d5b 100644 --- a/src/mongo/db/storage/key_string_to_bson_fuzzer.cpp +++ b/src/mongo/db/storage/key_string_to_bson_fuzzer.cpp @@ -116,7 +116,7 @@ extern "C" int LLVMFuzzerTestOneInput(const char* Data, size_t Size) { mongo::BSONObj obj = mongo::KeyString::toBsonSafe(&Data[2 + len], Size - (2 + len), ord, tb); // We want to make sure the generated BSON is valid - invariant(mongo::validateBSON(obj.objdata(), obj.objsize(), mongo::BSONVersion::kLatest)); + invariant(mongo::validateBSON(obj.objdata(), obj.objsize())); } catch (const mongo::AssertionException&) { // We need to catch exceptions caused by invalid inputs } diff --git a/src/mongo/db/storage/oplog_hack.cpp b/src/mongo/db/storage/oplog_hack.cpp index 19beb740a8d..ed71df2c8e6 100644 --- a/src/mongo/db/storage/oplog_hack.cpp +++ b/src/mongo/db/storage/oplog_hack.cpp @@ -68,7 +68,7 @@ StatusWith<RecordId> extractKey(const char* data, int len) { // Use the latest BSON validation version. Oplog entries are allowed to contain decimal data // even if decimal is disabled. if (kDebugBuild) - invariant(validateBSON(data, len, BSONVersion::kLatest).isOK()); + invariant(validateBSON(data, len).isOK()); const BSONObj obj(data); const BSONElement elem = obj["ts"]; diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp index fec912e569e..a9b221b3e64 100644 --- a/src/mongo/db/views/durable_view_catalog.cpp +++ b/src/mongo/db/views/durable_view_catalog.cpp @@ -136,7 +136,7 @@ BSONObj DurableViewCatalogImpl::_validateViewDefinition(OperationContext* opCtx, // Check the document is valid BSON, with only the expected fields. // Use the latest BSON validation version. Existing view definitions are allowed to contain // decimal data even if decimal is disabled. - fassert(40224, validateBSON(recordData.data(), recordData.size(), BSONVersion::kLatest)); + fassert(40224, validateBSON(recordData.data(), recordData.size())); BSONObj viewDefinition = recordData.toBson(); bool valid = true; diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp index d7bbac71c8e..c3e754b8771 100644 --- a/src/mongo/dbtests/jsobjtests.cpp +++ b/src/mongo/dbtests/jsobjtests.cpp @@ -505,7 +505,7 @@ public: bb << "a" << 1; BSONObj tmp = bb.asTempObj(); ASSERT(tmp.objsize() == 4 + (1 + 2 + 4) + 1); - ASSERT(tmp.valid(BSONVersion::kLatest)); + ASSERT(tmp.valid()); ASSERT(tmp.hasField("a")); ASSERT(!tmp.hasField("b")); ASSERT_BSONOBJ_EQ(tmp, BSON("a" << 1)); @@ -513,7 +513,7 @@ public: bb << "b" << 2; BSONObj obj = bb.obj(); ASSERT_EQUALS(obj.objsize(), 4 + (1 + 2 + 4) + (1 + 2 + 4) + 1); - ASSERT(obj.valid(BSONVersion::kLatest)); + ASSERT(obj.valid()); ASSERT(obj.hasField("a")); ASSERT(obj.hasField("b")); ASSERT_BSONOBJ_EQ(obj, BSON("a" << 1 << "b" << 2)); @@ -523,7 +523,7 @@ public: bb << "a" << GT << 1; BSONObj tmp = bb.asTempObj(); ASSERT(tmp.objsize() == 4 + (1 + 2 + (4 + 1 + 4 + 4 + 1)) + 1); - ASSERT(tmp.valid(BSONVersion::kLatest)); + ASSERT(tmp.valid()); ASSERT(tmp.hasField("a")); ASSERT(!tmp.hasField("b")); ASSERT_BSONOBJ_EQ(tmp, BSON("a" << BSON("$gt" << 1))); @@ -532,7 +532,7 @@ public: BSONObj obj = bb.obj(); ASSERT(obj.objsize() == 4 + (1 + 2 + (4 + 1 + 4 + 4 + 1)) + (1 + 2 + (4 + 1 + 4 + 4 + 1)) + 1); - ASSERT(obj.valid(BSONVersion::kLatest)); + ASSERT(obj.valid()); ASSERT(obj.hasField("a")); ASSERT(obj.hasField("b")); ASSERT_BSONOBJ_EQ(obj, BSON("a" << BSON("$gt" << 1) << "b" << BSON("$lt" << 2))); @@ -542,7 +542,7 @@ public: bb << "a" << 1; BSONObj tmp = bb.asTempObj(); ASSERT(tmp.objsize() == 4 + (1 + 2 + 4) + 1); - ASSERT(tmp.valid(BSONVersion::kLatest)); + ASSERT(tmp.valid()); ASSERT(tmp.hasField("a")); ASSERT(!tmp.hasField("b")); ASSERT_BSONOBJ_EQ(tmp, BSON("a" << 1)); @@ -554,7 +554,7 @@ public: } bb << "b" << arr.arr(); BSONObj obj = bb.obj(); - ASSERT(obj.valid(BSONVersion::kLatest)); + ASSERT(obj.valid()); ASSERT(obj.hasField("a")); ASSERT(obj.hasField("b")); } @@ -799,8 +799,8 @@ class Base { public: virtual ~Base() {} void run() { - ASSERT(valid().valid(BSONVersion::kLatest)); - ASSERT(!invalid().valid(BSONVersion::kLatest)); + ASSERT(valid().valid()); + ASSERT(!invalid().valid()); } protected: @@ -849,7 +849,7 @@ public: b.appendNull("a"); BSONObj o = b.done(); set(o, 4, mongo::Undefined); - ASSERT(o.valid(BSONVersion::kLatest)); + ASSERT(o.valid()); } }; @@ -1032,7 +1032,7 @@ public: void run() { const char data[] = {0x07, 0x00, 0x00, 0x00, char(type_), 'a', 0x00}; BSONObj o(data); - ASSERT(!o.valid(BSONVersion::kLatest)); + ASSERT(!o.valid()); } private: @@ -1371,7 +1371,7 @@ public: b2.done(); b1.append("f", 10.0); BSONObj ret = b1.done(); - ASSERT(ret.valid(BSONVersion::kLatest)); + ASSERT(ret.valid()); ASSERT(ret.woCompare(fromjson("{a:'bcd',foo:{ggg:44},f:10}")) == 0); } }; @@ -1392,7 +1392,7 @@ public: BSONObj o = BSON("now" << DATENOW); Date_t after = jsTime(); - ASSERT(o.valid(BSONVersion::kLatest)); + ASSERT(o.valid()); BSONElement e = o["now"]; ASSERT(e.type() == Date); @@ -1410,7 +1410,7 @@ public: b.appendTimeT("now", aTime); BSONObj o = b.obj(); - ASSERT(o.valid(BSONVersion::kLatest)); + ASSERT(o.valid()); BSONElement e = o["now"]; ASSERT_EQUALS(Date, e.type()); @@ -1424,8 +1424,8 @@ public: BSONObj min = BSON("a" << MINKEY); BSONObj max = BSON("b" << MAXKEY); - ASSERT(min.valid(BSONVersion::kLatest)); - ASSERT(max.valid(BSONVersion::kLatest)); + ASSERT(min.valid()); + ASSERT(max.valid()); BSONElement minElement = min["a"]; BSONElement maxElement = max["b"]; diff --git a/src/mongo/dbtests/jsontests.cpp b/src/mongo/dbtests/jsontests.cpp index f30c54ec3b4..435144bb5c4 100644 --- a/src/mongo/dbtests/jsontests.cpp +++ b/src/mongo/dbtests/jsontests.cpp @@ -624,7 +624,7 @@ void assertEquals(const std::string& json, } void checkEquivalence(const std::string& json, const BSONObj& bson) { - ASSERT(fromjson(json).valid(BSONVersion::kLatest)); + ASSERT(fromjson(json).valid()); assertEquals(json, bson, fromjson(json), "mode: json-to-bson"); assertEquals(json, bson, fromjson(tojson(bson)), "mode: <default>"); assertEquals(json, bson, fromjson(tojson(bson, LegacyStrict)), "mode: strict"); diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index 6920a1dd0c5..fbda40e576a 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -1268,7 +1268,7 @@ public: unique_ptr<DBClientCursor> cursor = _client.query(NamespaceString(ns), Query().sort("7")); while (cursor->more()) { BSONObj o = cursor->next(); - verify(o.valid(BSONVersion::kLatest)); + verify(o.valid()); } } void run() { diff --git a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp index 1d83ec54aff..683c3edfb96 100644 --- a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp +++ b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp @@ -189,7 +189,7 @@ protected: // convert the message into an OpMessage to examine its BSON auto outputOpMsg = mongo::OpMsg::parseOwned(outputMessage); - ASSERT(outputOpMsg.body.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputOpMsg.body.valid()); return outputOpMsg.body; } @@ -400,7 +400,7 @@ TEST_F(MongodbCAPITest, ReadDB) { auto outputBSON = performRpc(client, findMsg); - ASSERT(outputBSON.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON.valid()); ASSERT(outputBSON.hasField("cursor")); ASSERT(outputBSON.getField("cursor").embeddedObject().hasField("firstBatch")); mongo::BSONObj arrObj = @@ -425,7 +425,7 @@ TEST_F(MongodbCAPITest, InsertAndRead) { "{insert: 'collection_name', documents: [{firstName: 'Mongo', lastName: 'DB', age: 10}]}"); auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj); auto outputBSON1 = performRpc(client, insertOpMsg); - ASSERT(outputBSON1.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON1.valid()); ASSERT(outputBSON1.hasField("n")); ASSERT(outputBSON1.getIntField("n") == 1); ASSERT(outputBSON1.hasField("ok")); @@ -434,7 +434,7 @@ TEST_F(MongodbCAPITest, InsertAndRead) { mongo::BSONObj findObj = mongo::fromjson("{find: 'collection_name', limit: 1}"); auto findMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", findObj); auto outputBSON2 = performRpc(client, findMsg); - ASSERT(outputBSON2.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON2.valid()); ASSERT(outputBSON2.hasField("cursor")); ASSERT(outputBSON2.getField("cursor").embeddedObject().hasField("firstBatch")); mongo::BSONObj arrObj = @@ -460,7 +460,7 @@ TEST_F(MongodbCAPITest, InsertAndReadDifferentClients) { "{insert: 'collection_name', documents: [{firstName: 'Mongo', lastName: 'DB', age: 10}]}"); auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj); auto outputBSON1 = performRpc(client1, insertOpMsg); - ASSERT(outputBSON1.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON1.valid()); ASSERT(outputBSON1.hasField("n")); ASSERT(outputBSON1.getIntField("n") == 1); ASSERT(outputBSON1.hasField("ok")); @@ -469,7 +469,7 @@ TEST_F(MongodbCAPITest, InsertAndReadDifferentClients) { mongo::BSONObj findObj = mongo::fromjson("{find: 'collection_name', limit: 1}"); auto findMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", findObj); auto outputBSON2 = performRpc(client2, findMsg); - ASSERT(outputBSON2.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON2.valid()); ASSERT(outputBSON2.hasField("cursor")); ASSERT(outputBSON2.getField("cursor").embeddedObject().hasField("firstBatch")); mongo::BSONObj arrObj = @@ -494,7 +494,7 @@ TEST_F(MongodbCAPITest, InsertAndDelete) { "age: 10}]}"); auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj); auto outputBSON1 = performRpc(client, insertOpMsg); - ASSERT(outputBSON1.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON1.valid()); ASSERT(outputBSON1.hasField("n")); ASSERT(outputBSON1.getIntField("n") == 1); ASSERT(outputBSON1.hasField("ok")); @@ -507,7 +507,7 @@ TEST_F(MongodbCAPITest, InsertAndDelete) { "1}]}"); auto deleteOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", deleteObj); auto outputBSON2 = performRpc(client, deleteOpMsg); - ASSERT(outputBSON2.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON2.valid()); ASSERT(outputBSON2.hasField("n")); ASSERT(outputBSON2.getIntField("n") == 1); ASSERT(outputBSON2.hasField("ok")); @@ -523,7 +523,7 @@ TEST_F(MongodbCAPITest, InsertAndUpdate) { "age: 10}]}"); auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj); auto outputBSON1 = performRpc(client, insertOpMsg); - ASSERT(outputBSON1.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON1.valid()); ASSERT(outputBSON1.hasField("n")); ASSERT(outputBSON1.getIntField("n") == 1); ASSERT(outputBSON1.hasField("ok")); @@ -536,7 +536,7 @@ TEST_F(MongodbCAPITest, InsertAndUpdate) { "{age: 5}}}]}"); auto updateOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", updateObj); auto outputBSON2 = performRpc(client, updateOpMsg); - ASSERT(outputBSON2.valid(mongo::BSONVersion::kLatest)); + ASSERT(outputBSON2.valid()); ASSERT(outputBSON2.hasField("ok")); ASSERT(outputBSON2.getField("ok").numberDouble() == 1.0); ASSERT(outputBSON2.hasField("nModified")); diff --git a/src/mongo/rpc/object_check.h b/src/mongo/rpc/object_check.h index a15c7e1a0bc..26bc175539e 100644 --- a/src/mongo/rpc/object_check.h +++ b/src/mongo/rpc/object_check.h @@ -45,16 +45,9 @@ class Status; */ template <> struct Validator<BSONObj> { - inline static BSONVersion enabledBSONVersion() { - // The enabled BSON version is always the latest BSON version if no new BSON types have been - // added during the release. Otherwise, the BSON version returned should be controlled - // through the featureCompatibilityVersion. - return BSONVersion::kLatest; - } inline static Status validateLoad(const char* ptr, size_t length) { - return serverGlobalParams.objcheck ? validateBSON(ptr, length, enabledBSONVersion()) - : Status::OK(); + return serverGlobalParams.objcheck ? validateBSON(ptr, length) : Status::OK(); } static Status validateStore(const BSONObj& toStore); diff --git a/src/mongo/rpc/protocol_fuzzer.cpp b/src/mongo/rpc/protocol_fuzzer.cpp index e6bbbf14630..19876d0ef47 100644 --- a/src/mongo/rpc/protocol_fuzzer.cpp +++ b/src/mongo/rpc/protocol_fuzzer.cpp @@ -52,7 +52,7 @@ struct CompressionInfrastructure { }; void validateBSON(const BSONObj& obj) { - validateBSON(obj.objdata(), obj.objsize(), BSONVersion::kLatest).ignore(); + validateBSON(obj.objdata(), obj.objsize()).ignore(); } void doFuzzing(ConstDataRangeCursor fuzzedData) try { diff --git a/src/mongo/shell/shell_utils_extended.cpp b/src/mongo/shell/shell_utils_extended.cpp index f46f01bccd0..cc415ae51b0 100644 --- a/src/mongo/shell/shell_utils_extended.cpp +++ b/src/mongo/shell/shell_utils_extended.cpp @@ -429,7 +429,7 @@ BSONObj readDumpFile(const BSONObj& a, void*) { uassertStatusOK(swObj); const auto obj = swObj.getValue(); - uassertStatusOK(validateBSON(obj.objdata(), valid, BSONVersion::kLatest)); + uassertStatusOK(validateBSON(obj.objdata(), valid)); array.append(obj); } |