Skip to content

Commit 4ad963d

Browse files
Andrew WittenkevinAlbs
authored andcommitted
CDRIVER-3539 adds null checks
Adds null checks after calls to _mongoc_cluster_create_server_stream.
1 parent 08d3f68 commit 4ad963d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/libmongoc/src/mongoc/mongoc-cluster-cyrus.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ _mongoc_cluster_auth_node_cyrus (mongoc_cluster_t *cluster,
8484
server_stream = _mongoc_cluster_create_server_stream (
8585
cluster->client->topology, sd->id, stream, error);
8686

87+
if (!server_stream) {
88+
bson_destroy (&cmd);
89+
goto failure;
90+
}
91+
8792
if (!mongoc_cmd_parts_assemble (&parts, server_stream, error)) {
8893
mongoc_server_stream_cleanup (server_stream);
8994
bson_destroy (&cmd);

src/libmongoc/src/mongoc/mongoc-cluster.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,11 @@ _mongoc_cluster_auth_node_cr (mongoc_cluster_t *cluster,
10621062
parts.prohibit_lsid = true;
10631063
server_stream = _mongoc_cluster_create_server_stream (
10641064
cluster->client->topology, sd->id, stream, error);
1065+
if (!server_stream) {
1066+
bson_destroy (&command);
1067+
bson_destroy (&reply);
1068+
RETURN (false);
1069+
}
10651070

10661071
if (!mongoc_cluster_run_command_parts (
10671072
cluster, server_stream, &parts, &reply, error)) {
@@ -1191,6 +1196,12 @@ _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster,
11911196
parts.prohibit_lsid = true;
11921197
server_stream = _mongoc_cluster_create_server_stream (
11931198
cluster->client->topology, sd->id, stream, error);
1199+
if (!server_stream) {
1200+
bson_destroy (&b);
1201+
bson_destroy (&reply);
1202+
return false;
1203+
}
1204+
11941205
ret = mongoc_cluster_run_command_parts (
11951206
cluster, server_stream, &parts, &reply, error);
11961207
mongoc_server_stream_cleanup (server_stream);
@@ -1299,6 +1310,12 @@ _mongoc_cluster_auth_node_x509 (mongoc_cluster_t *cluster,
12991310
parts.prohibit_lsid = true;
13001311
server_stream = _mongoc_cluster_create_server_stream (
13011312
cluster->client->topology, sd->id, stream, error);
1313+
if (!server_stream) {
1314+
bson_destroy (&cmd);
1315+
bson_destroy (&reply);
1316+
return false;
1317+
}
1318+
13021319
ret = mongoc_cluster_run_command_parts (
13031320
cluster, server_stream, &parts, &reply, error);
13041321
mongoc_server_stream_cleanup (server_stream);
@@ -1429,7 +1446,11 @@ _mongoc_cluster_run_scram_command (mongoc_cluster_t *cluster,
14291446
parts.prohibit_lsid = true;
14301447
server_stream = _mongoc_cluster_create_server_stream (
14311448
cluster->client->topology, server_id, stream, error);
1432-
BSON_ASSERT (server_stream);
1449+
if (!server_stream) {
1450+
bson_destroy (reply);
1451+
return false;
1452+
}
1453+
14331454
if (!mongoc_cluster_run_command_parts (
14341455
cluster, server_stream, &parts, reply, error)) {
14351456
mongoc_server_stream_cleanup (server_stream);
@@ -3021,6 +3042,10 @@ mongoc_cluster_check_interval (mongoc_cluster_t *cluster, uint32_t server_id)
30213042
parts.prohibit_lsid = true;
30223043
server_stream = _mongoc_cluster_create_server_stream (
30233044
cluster->client->topology, server_id, stream, &error);
3045+
if (!server_stream) {
3046+
bson_destroy (&command);
3047+
return false;
3048+
}
30243049
r = mongoc_cluster_run_command_parts (
30253050
cluster, server_stream, &parts, NULL, &error);
30263051

0 commit comments

Comments
 (0)