Skip to content

Commit 88bf01a

Browse files
committed
CDRIVER-5736 do not assert on failure to create OpenSSL context (#1750)
* CDRIVER-5736 add regression test * do not assert context is non-NULL
1 parent 32b693b commit 88bf01a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/libmongoc/src/mongoc/mongoc-stream-tls-openssl.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,10 @@ mongoc_stream_t *
882882
mongoc_stream_tls_openssl_new_with_context (
883883
mongoc_stream_t *base_stream, const char *host, mongoc_ssl_opt_t *opt, int client, SSL_CTX *ssl_ctx)
884884
{
885-
BSON_ASSERT_PARAM (ssl_ctx);
885+
// `ssl_ctx` may be NULL if creating the context failed. Return NULL to signal failure.
886+
if (!ssl_ctx) {
887+
return NULL;
888+
}
886889
SSL_CTX_up_ref (ssl_ctx);
887890

888891
return create_stream_with_ctx (base_stream, host, opt, client, ssl_ctx);

src/libmongoc/tests/test-mongoc-ssl.c

+10
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ test_mongoc_ssl_opts_cleanup_zero (void)
199199
_mongoc_ssl_opts_cleanup (&ssl_opt, false /* free_internal */);
200200
}
201201

202+
// `test_non_existant_cafile` is a regression test for CDRIVER-5736.
203+
static void
204+
test_non_existant_cafile (void)
205+
{
206+
mongoc_client_t *client = mongoc_client_new ("mongodb://localhost:27017/?tls=true&tlsCAFile=/nonexistant/ca.pem");
207+
ASSERT (!mongoc_client_command_simple (client, "admin", tmp_bson ("{'ping': 1}"), NULL, NULL, NULL));
208+
mongoc_client_destroy (client);
209+
}
210+
202211
#endif /* MONGOC_ENABLE_SSL */
203212

204213
void
@@ -207,5 +216,6 @@ test_ssl_install (TestSuite *suite)
207216
#ifdef MONGOC_ENABLE_SSL
208217
TestSuite_Add (suite, "/ssl_opt/from_bson", test_mongoc_ssl_opts_from_bson);
209218
TestSuite_Add (suite, "/ssl_opt/cleanup", test_mongoc_ssl_opts_cleanup_zero);
219+
TestSuite_Add (suite, "/ssl_opt/non-existant-cafile", test_non_existant_cafile);
210220
#endif /* MONGOC_ENABLE_SSL */
211221
}

0 commit comments

Comments
 (0)