Skip to content

Commit e353c3e

Browse files
jmikolaajdavis
authored andcommitted
CDRIVER-2060: Validate that localThresholdMS URI option is non-negative
1 parent dcff494 commit e353c3e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/mongoc/mongoc-uri.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,11 @@ mongoc_uri_get_local_threshold_option (const mongoc_uri_t *uri)
12651265
BSON_ITER_HOLDS_INT32 (&iter)) {
12661266

12671267
retval = bson_iter_int32 (&iter);
1268+
1269+
if (retval < 0) {
1270+
MONGOC_WARNING ("Invalid localThresholdMS: %d", retval);
1271+
retval = MONGOC_TOPOLOGY_LOCAL_THRESHOLD_MS;
1272+
}
12681273
}
12691274

12701275
return retval;

tests/test-mongoc-uri.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,19 @@ test_mongoc_uri_local_threshold_ms (void)
10891089
ASSERT_CMPINT (mongoc_uri_get_local_threshold_option (uri), ==, 99);
10901090

10911091
mongoc_uri_destroy(uri);
1092+
1093+
1094+
uri = mongoc_uri_new(
1095+
"mongodb://localhost/?" MONGOC_URI_LOCALTHRESHOLDMS "=-1");
1096+
1097+
/* localthresholdms is invalid, return the default */
1098+
capture_logs (true);
1099+
ASSERT_CMPINT (mongoc_uri_get_local_threshold_option (uri), ==,
1100+
MONGOC_TOPOLOGY_LOCAL_THRESHOLD_MS);
1101+
ASSERT_CAPTURED_LOG ("mongoc_uri_get_local_threshold_option",
1102+
MONGOC_LOG_LEVEL_WARNING, "Invalid localThresholdMS: -1");
1103+
1104+
mongoc_uri_destroy(uri);
10921105
}
10931106

10941107
void

0 commit comments

Comments
 (0)