[CDRIVER-3476] Lowercase options before storing when set via mongoc_uri_set_option_as_* Created: 08/Jan/20  Updated: 28/Oct/23  Resolved: 29/Jun/20

Status: Closed
Project: C Driver
Component/s: libmongoc, uri
Affects Version/s: None
Fix Version/s: 1.17.0-rc0, 1.17.0

Type: Improvement Priority: Major - P3
Reporter: Kevin Albertson Assignee: Andrew Witten (Inactive)
Resolution: Fixed Votes: 0
Labels: new-eng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-3723 Validate URI options on client/client... Closed
is related to PHPC-991 Handle duplicates in URI options array Closed

 Description   

When options are parsed from the connection string passed to mongoc_uri_new, they are internally stored on uri->options after being converted to lowercase in mongoc_uri_split_option here.

However, options that are set via the mongoc_uri_set_option_as_* are not lowercased before being stored in uri->options.

For consistency, let's lowercase options before storing them in the mongoc_uri_set_options_as_* functions. This should allow us to remove a lot of case sensitivity checks in URI related functions.

In addition, there may be a bug caused by the inconsistent casing. Specifying a mongodb+srv URI can result in options being added to a mongoc_uri_t after polling for TXT records in client construction. See the Initial Seedlist Spec for background. TXT records are polled for in mongoc_topology_new here.

mongoc_uri_options_validate_names, is used to check for canonical/non-canonical mismatches between uri->options and options being added. It appears to assume that both cases of the options are the same. So I think this scenario could be a bug:

uri = mongoc_uri_new("mongodb+srv://host")
mongoc_uri_set_option_as_bool (uri, "TLS", true)
client = mongoc_client_new_from_uri (uri)
/* TXT record comes back with option ssl=false. mongoc_uri_options_validate_names does not find the conflicting options because it expects TLS to be stored in lowercase. */

Perhaps adding a test should be a part of this work. We don't have automated SRV tests, but we could simulate the TXT records by calling the private function mongoc_uri_parse_options.



 Comments   
Comment by Githook User [ 11/Jul/20 ]

Author:

{'name': 'Andrew Witten', 'email': 'andrew.witten@mongodb.com', 'username': 'awitten1'}

Message: CDRIVER-3476 lower case options (#645)

Comment by Githook User [ 26/Jun/20 ]

Author:

{'name': 'Andrew Witten', 'email': 'andrew.witten@mongodb.com', 'username': 'awitten1'}

Message: CDRIVER-3476 lower case options (#645)

Comment by Andrew Witten (Inactive) [ 25/Jun/20 ]

PR:  https://github.com/mongodb/mongo-c-driver/pull/645

Generated at Wed Feb 07 21:18:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.