Skip to content

Commit 48fae84

Browse files
committed
CDRIVER-2342 check for null user in _mongoc_scram_start
1 parent baf5040 commit 48fae84

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ set(test-libmongoc-sources
733733
${SOURCE_DIR}/tests/test-mongoc-read-prefs.c
734734
${SOURCE_DIR}/tests/test-mongoc-rpc.c
735735
${SOURCE_DIR}/tests/test-mongoc-sample-commands.c
736+
${SOURCE_DIR}/tests/test-mongoc-scram.c
736737
${SOURCE_DIR}/tests/test-mongoc-sdam.c
737738
${SOURCE_DIR}/tests/test-mongoc-sdam-monitoring.c
738739
${SOURCE_DIR}/tests/test-mongoc-server-selection.c

src/mongoc/mongoc-scram.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ _mongoc_scram_start (mongoc_scram_t *scram,
172172
BSON_ASSERT (outbufmax);
173173
BSON_ASSERT (outbuflen);
174174

175+
if (!scram->user) {
176+
bson_set_error (error,
177+
MONGOC_ERROR_SCRAM,
178+
MONGOC_ERROR_SCRAM_PROTOCOL_ERROR,
179+
"SCRAM Failure: username is not set");
180+
goto FAIL;
181+
}
182+
175183
/* auth message is as big as the outbuf just because */
176184
scram->auth_message = (uint8_t *) bson_malloc (outbufmax);
177185
scram->auth_messagemax = outbufmax;

tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ test_libmongoc_SOURCES = \
9494
tests/test-mongoc-rpc.c \
9595
tests/test-mongoc-socket.c \
9696
tests/test-mongoc-sample-commands.c \
97+
tests/test-mongoc-scram.c \
9798
tests/test-mongoc-sdam.c \
9899
tests/test-mongoc-sdam-monitoring.c \
99100
tests/test-mongoc-server-selection.c \

tests/test-libmongoc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ test_rpc_install (TestSuite *suite);
9393
extern void
9494
test_samples_install (TestSuite *suite);
9595
extern void
96+
test_scram_install (TestSuite *suite);
97+
extern void
9698
test_sdam_install (TestSuite *suite);
9799
extern void
98100
test_sdam_monitoring_install (TestSuite *suite);
@@ -2003,6 +2005,7 @@ main (int argc, char *argv[])
20032005
test_topology_scanner_install (&suite);
20042006
test_topology_reconcile_install (&suite);
20052007
test_samples_install (&suite);
2008+
test_scram_install (&suite);
20062009
test_sdam_install (&suite);
20072010
test_sdam_monitoring_install (&suite);
20082011
test_server_selection_install (&suite);

tests/test-mongoc-scram.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <mongoc.h>
2+
3+
#include "mongoc-scram-private.h"
4+
5+
#include "TestSuite.h"
6+
7+
#ifdef MONGOC_ENABLE_SSL
8+
static void
9+
test_mongoc_scram_step_username_not_set (void)
10+
{
11+
mongoc_scram_t scram;
12+
bool success;
13+
uint8_t buf[4096] = {0};
14+
uint32_t buflen = 0;
15+
bson_error_t error;
16+
17+
_mongoc_scram_init (&scram);
18+
_mongoc_scram_set_pass (&scram, "password");
19+
20+
success = _mongoc_scram_step (
21+
&scram, buf, buflen, buf, sizeof buf, &buflen, &error);
22+
23+
ASSERT (!success);
24+
ASSERT_ERROR_CONTAINS (error,
25+
MONGOC_ERROR_SCRAM,
26+
MONGOC_ERROR_SCRAM_PROTOCOL_ERROR,
27+
"SCRAM Failure: username is not set");
28+
29+
_mongoc_scram_destroy (&scram);
30+
}
31+
#endif
32+
33+
34+
void
35+
test_scram_install (TestSuite *suite)
36+
{
37+
#ifdef MONGOC_ENABLE_SSL
38+
TestSuite_Add (suite,
39+
"/scram/username_not_set",
40+
test_mongoc_scram_step_username_not_set);
41+
#endif
42+
}

0 commit comments

Comments
 (0)