diff options
author | Moustafa Maher <m.maher@10gen.com> | 2021-01-24 03:36:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-26 00:47:49 +0000 |
commit | 593de2a7ed6e6717ed35112c63ab3ee38b825851 (patch) | |
tree | 93f5f275b08b4006f798c953a938186c3ec8a5a9 | |
parent | 57aa9e6106905a8969af5b997e2b316ce2d71b62 (diff) | |
download | mongo-593de2a7ed6e6717ed35112c63ab3ee38b825851.tar.gz |
SERVER-54003 Validate BSON type to be array when parsing BSON object to Array
-rw-r--r-- | buildscripts/idl/idl/generator.py | 4 | ||||
-rw-r--r-- | jstests/core/kill_cursors.js | 2 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_union_with_test.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/query/killcursors_request_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/tenant_migration_recipient_service.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/storage_timestamp_tests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/idl/idl_test.cpp | 21 |
7 files changed, 29 insertions, 9 deletions
diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py index 80fce32a44a..c2d198e50cf 100644 --- a/buildscripts/idl/idl/generator.py +++ b/buildscripts/idl/idl/generator.py @@ -1290,7 +1290,9 @@ class _CppSourceFileWriter(_CppFileWriterBase): """Generate the C++ deserializer piece for a field.""" # pylint: disable=too-many-arguments if field.type.is_array: - self._gen_usage_check(field, bson_element, field_usage_check) + predicate = "MONGO_likely(ctxt.checkAndAssertType(%s, Array))" % (bson_element) + with self._predicate(predicate): + self._gen_usage_check(field, bson_element, field_usage_check) self._gen_array_deserializer(field, bson_element, field.type) return diff --git a/jstests/core/kill_cursors.js b/jstests/core/kill_cursors.js index 09184005c11..8c240a71def 100644 --- a/jstests/core/kill_cursors.js +++ b/jstests/core/kill_cursors.js @@ -32,7 +32,7 @@ assert.commandFailedWithCode(cmdRes, ErrorCodes.BadValue); // killCursors command should fail if the cursors parameter is not an array. cmdRes = db.runCommand({killCursors: coll.getName(), cursors: {a: NumberLong(123), b: NumberLong(456)}}); -assert.commandFailedWithCode(cmdRes, [40422]); +assert.commandFailedWithCode(cmdRes, ErrorCodes.TypeMismatch); // killCursors command should report that zero cursors were killed if the cursors parameter is an // empty array. diff --git a/src/mongo/db/pipeline/document_source_union_with_test.cpp b/src/mongo/db/pipeline/document_source_union_with_test.cpp index 8fa361ce540..48068466824 100644 --- a/src/mongo/db/pipeline/document_source_union_with_test.cpp +++ b/src/mongo/db/pipeline/document_source_union_with_test.cpp @@ -282,7 +282,7 @@ TEST_F(DocumentSourceUnionWithTest, ParseErrors) { .firstElement(), getExpCtx()), AssertionException, - 10065); + ErrorCodes::TypeMismatch); ASSERT_THROWS_CODE(DocumentSourceUnionWith::createFromBson( BSON("$unionWith" << BSON("coll" << nsToUnionWith.coll() << "pipeline" << BSON("not" @@ -290,7 +290,7 @@ TEST_F(DocumentSourceUnionWithTest, ParseErrors) { .firstElement(), getExpCtx()), AssertionException, - 40422); + ErrorCodes::TypeMismatch); } TEST_F(DocumentSourceUnionWithTest, PropagatePauses) { diff --git a/src/mongo/db/query/killcursors_request_test.cpp b/src/mongo/db/query/killcursors_request_test.cpp index 2a63ba50769..5535fa2c56f 100644 --- a/src/mongo/db/query/killcursors_request_test.cpp +++ b/src/mongo/db/query/killcursors_request_test.cpp @@ -89,7 +89,8 @@ TEST(KillCursorsRequestTest, parseCursorFieldNotArray) { << "coll" << "cursors" << CursorId(123) << "$db" << "db"); - ASSERT_THROWS_CODE(KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, 10065); + ASSERT_THROWS_CODE( + KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, ErrorCodes::TypeMismatch); } TEST(KillCursorsRequestTest, parseCursorFieldArrayWithNonCursorIdValue) { diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp index 3f3b8d0f408..a63f2094bd7 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp @@ -579,7 +579,7 @@ void TenantMigrationRecipientService::Instance::_startOplogFetcher() { // The config is only used for setting the awaitData timeout; the defaults are fine. ReplSetConfig::parse(BSON("_id" << "dummy" - << "version" << 1 << "members" << BSONObj())), + << "version" << 1 << "members" << BSONArray(BSONObj()))), // We do not need to check the rollback ID. ReplicationProcess::kUninitializedRollbackId, tenantMigrationOplogFetcherBatchSize, diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp index 7cdc62217cc..c1ccb5df053 100644 --- a/src/mongo/dbtests/storage_timestamp_tests.cpp +++ b/src/mongo/dbtests/storage_timestamp_tests.cpp @@ -738,7 +738,7 @@ public: << "ns" << "test.$cmd" << "wall" << Date_t() << "o" - << BSON("applyOps" << BSONArrayBuilder().obj())))), + << BSON("applyOps" << BSONArrayBuilder().arr())))), repl::OplogApplication::Mode::kApplyOpsCmd, &result)); } diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp index 6ab160786ed..cdbfeb70210 100644 --- a/src/mongo/idl/idl_test.cpp +++ b/src/mongo/idl/idl_test.cpp @@ -1057,8 +1057,25 @@ TEST(IDLArrayTests, TestBadArrays) { } } -// Positive: Test arrays with good field names but made with BSONObjBuilder -TEST(IDLArrayTests, TestGoodArrays) { +// Negative: Test arrays with good field names but made with BSONObjBuilder::subobjStart +TEST(IDLArrayTests, TestGoodArraysWithObjectType) { + IDLParserErrorContext ctxt("root"); + + { + BSONObjBuilder builder; + { + BSONObjBuilder subBuilder(builder.subobjStart("field1")); + subBuilder.append("0", 1); + subBuilder.append("1", 2); + } + + auto testDoc = builder.obj(); + ASSERT_THROWS(Simple_int_array::parse(ctxt, testDoc), AssertionException); + } +} + +// Positive: Test arrays with good field names but made with BSONObjBuilder::subarrayStart +TEST(IDLArrayTests, TestGoodArraysWithArrayType) { IDLParserErrorContext ctxt("root"); { |