[CXX-1063] mongocxx::uri doesn't validate URI on construction Created: 03/Oct/16  Updated: 15/Nov/16  Resolved: 03/Nov/16

Status: Closed
Project: C++ Driver
Component/s: Implementation
Affects Version/s: 3.0.1
Fix Version/s: 3.0.3

Type: Bug Priority: Major - P3
Reporter: Armin Ball [X] Assignee: David Golden
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Uncatchable Error during initialisation. try

{ . . . }catch(...){ . . . }

If I input wrong input parameters like: "mongodb://:@:/" The my program exits with -1. Last output is: src/mongoc/mongoc-topology.c:155 mongoc_topology_new(): precondition failed: uri

If the version of the new c++ driver is important, pleas tell me how I can find out the library version of my compiled libraries.

CODE:
mongocxx::client conn; // defined in class header file
SomeClass::someClass(){
std::stringstream stmMongoDbUri;
stmMongoDbUri
<< "mongodb://" //<< MyConfiguration.dbUser
<< ":" //<< MyConfiguration.dbPassword
<< "@" //<< MyConfiguration.dbHost
<< ":" //<< MyConfiguration.dbPort
<< "/" //<< MyConfiguration.databaseName;

std::string strMongoDbUri (std::istreambuf_iterator<char>(stmMongoDbUri), {});

printf("47 - Streamconten Mongo DB Config > %s <", strMongoDbUri.c_str() );

// src/mongoc/mongoc-topology.c:155 mongoc_topology_new(): precondition failed: uri
// No valid connection established / invalid string... ka...
//[strMongoDbUri] = "mongodb://:@:/"
conn = mongocxx::client(mongocxx::uri(strMongoDbUri));
...
}



 Comments   
Comment by Githook User [ 08/Nov/16 ]

Author:

{u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}

Message: CXX-1063 Throw exception for invalid URIs
Branch: 3.1-dev
https://github.com/mongodb/mongo-cxx-driver/commit/ed9e97b051d839145808056c9a7e561448cd903e

Comment by Githook User [ 03/Nov/16 ]

Author:

{u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}

Message: CXX-1063 Throw exception for invalid URIs
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/ed9e97b051d839145808056c9a7e561448cd903e

Comment by David Golden [ 01/Nov/16 ]

https://mongodbcr.appspot.com/98920002/

Comment by Armin Ball [X] [ 03/Oct/16 ]

& Thank you!
Controlling arguments, got something in the mind:
find_and_update(view,view,view);
If you change the order of the arguments it crashes also very very downstairs. I'm sorry I can't find the code anymore. It was late at night.
Maybe have a brief look at that if some can reproduce it in a minute. If not, I'll keep watching for this faulty code snipped.
I'm sure for 80% that the upper description is correct.

Comment by David Golden [ 03/Oct/16 ]

Good catch. It looks like we're not validating URIs. We'll address this in the next release.

Regarding versions, it shouldn't matter for this, but you can check with mongocxx/config/version.h:

  • MONGOCXX_VERSION_MAJOR
  • MONGOCXX_VERSION_MINOR
  • MONGOCXX_VERSION_PATCH
  • MONGOCXX_VERSION_EXTRA

I'll open a ticket to better expose and/or document those.

Generated at Wed Feb 07 22:01:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.