Skip to content

Commit d1a6795

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

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
@@ -1230,6 +1230,11 @@ mongoc_uri_get_local_threshold_option (const mongoc_uri_t *uri)
12301230
BSON_ITER_HOLDS_INT32 (&iter)) {
12311231

12321232
retval = bson_iter_int32 (&iter);
1233+
1234+
if (retval < 0) {
1235+
MONGOC_WARNING ("Invalid localThresholdMS: %d", retval);
1236+
retval = MONGOC_TOPOLOGY_LOCAL_THRESHOLD_MS;
1237+
}
12331238
}
12341239

12351240
return retval;

tests/test-mongoc-uri.c

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

905905
mongoc_uri_destroy(uri);
906+
907+
908+
uri = mongoc_uri_new(
909+
"mongodb://localhost/?" MONGOC_URI_LOCALTHRESHOLDMS "=-1");
910+
911+
/* localthresholdms is invalid, return the default */
912+
capture_logs (true);
913+
ASSERT_CMPINT (mongoc_uri_get_local_threshold_option (uri), ==,
914+
MONGOC_TOPOLOGY_LOCAL_THRESHOLD_MS);
915+
ASSERT_CAPTURED_LOG ("mongoc_uri_get_local_threshold_option",
916+
MONGOC_LOG_LEVEL_WARNING, "Invalid localThresholdMS: -1");
917+
918+
mongoc_uri_destroy(uri);
906919
}
907920

908921

0 commit comments

Comments
 (0)