@@ -1332,6 +1332,39 @@ test_ismaster_retry_pooled_timeout_fail (void)
1332
1332
}
1333
1333
1334
1334
1335
+ /* ensure there's no invalid access if a null bson_error_t pointer is passed
1336
+ * to mongoc_topology_compatible () */
1337
+ static void
1338
+ test_compatible_null_error_pointer (void )
1339
+ {
1340
+ mock_server_t * server ;
1341
+ mongoc_client_t * client ;
1342
+ mongoc_topology_description_t * td ;
1343
+ bson_error_t error ;
1344
+
1345
+ server = mock_server_with_autoismaster (1 ); /* incompatible */
1346
+ mock_server_run (server );
1347
+ client = mongoc_client_new_from_uri (mock_server_get_uri (server ));
1348
+ td = & client -> topology -> description ;
1349
+
1350
+ /* trigger connection, fails due to incompatibility */
1351
+ ASSERT (!mongoc_client_command_simple (
1352
+ client , "admin" , tmp_bson ("{'ismaster': 1}" ), NULL , NULL , & error ));
1353
+
1354
+ ASSERT_ERROR_CONTAINS (error ,
1355
+ MONGOC_ERROR_PROTOCOL ,
1356
+ MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION ,
1357
+ "" );
1358
+
1359
+ /* null error pointer is ok */
1360
+ ASSERT (!mongoc_topology_compatible (
1361
+ td , NULL /* read prefs */ , NULL /* error */ ));
1362
+
1363
+ mongoc_client_destroy (client );
1364
+ mock_server_destroy (server );
1365
+ }
1366
+
1367
+
1335
1368
void
1336
1369
test_topology_install (TestSuite * suite )
1337
1370
{
@@ -1438,4 +1471,7 @@ test_topology_install (TestSuite *suite)
1438
1471
TestSuite_AddMockServerTest (suite ,
1439
1472
"/Topology/ismaster_retry/pooled/timeout/fail" ,
1440
1473
test_ismaster_retry_pooled_timeout_fail );
1474
+ TestSuite_AddMockServerTest (suite ,
1475
+ "/Topology/compatible_null_error_pointer" ,
1476
+ test_compatible_null_error_pointer );
1441
1477
}
0 commit comments