File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -341,6 +341,11 @@ _mongoc_scram_start (
341
341
goto FAIL ;
342
342
}
343
343
344
+ if (!scram -> pass ) {
345
+ // Apply an empty string as a default.
346
+ scram -> pass = bson_strdup ("" );
347
+ }
348
+
344
349
/* auth message is as big as the outbuf just because */
345
350
scram -> auth_message = (uint8_t * ) bson_malloc (outbufmax );
346
351
scram -> auth_messagemax = outbufmax ;
@@ -994,6 +999,7 @@ _mongoc_scram_step (mongoc_scram_t *scram,
994
999
bool
995
1000
_mongoc_sasl_prep_required (const char * str )
996
1001
{
1002
+ BSON_ASSERT_PARAM (str );
997
1003
unsigned char c ;
998
1004
while (* str ) {
999
1005
c = (unsigned char ) * str ;
Original file line number Diff line number Diff line change @@ -718,6 +718,25 @@ test_mongoc_saslprep_auth (void *ctx)
718
718
_drop_saslprep_users ();
719
719
}
720
720
721
+ // `test_mongoc_scram_empty_password` is a regression test for CDRIVER-5550.
722
+ static void
723
+ test_mongoc_scram_empty_password (void * ctx )
724
+ {
725
+ BSON_UNUSED (ctx );
726
+ char * user = test_framework_get_admin_user ();
727
+ char * uri_str = test_framework_get_uri_str_no_auth ("admin" );
728
+ mongoc_uri_t * uri = mongoc_uri_new (uri_str );
729
+ mongoc_uri_set_username (uri , user );
730
+
731
+ // Expect an auth failure (not a crash):
732
+ _try_auth_from_uri (false /* pooled */ , uri , MONGOC_TEST_AUTH_ERROR );
733
+ _try_auth_from_uri (true /* pooled */ , uri , MONGOC_TEST_AUTH_ERROR );
734
+
735
+ mongoc_uri_destroy (uri );
736
+ bson_free (uri_str );
737
+ bson_free (user );
738
+ }
739
+
721
740
void
722
741
test_scram_install (TestSuite * suite )
723
742
{
@@ -751,4 +770,12 @@ test_scram_install (TestSuite *suite)
751
770
test_framework_skip_if_no_auth ,
752
771
_skip_if_no_sha256 ,
753
772
TestSuite_CheckLive );
773
+ TestSuite_AddFull (suite ,
774
+ "/scram/empty_password" ,
775
+ test_mongoc_scram_empty_password ,
776
+ NULL /* dtor */ ,
777
+ NULL /* ctx */ ,
778
+ test_framework_skip_if_no_auth ,
779
+ _skip_if_no_sha256 ,
780
+ TestSuite_CheckLive );
754
781
}
You can’t perform that action at this time.
0 commit comments