-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.0.1
-
Component/s: Implementation
-
None
This problem is related to this code in find_and_modify:
bool r = mongocxx::libmongoc::collection_find_and_modify_with_opts(
collection, bson_filter.bson(), opts, reply.bson(), &error);
if (!r) {
auto gle = mongocxx::libmongoc::collection_get_last_error(collection);
mongocxx::throw_exception<mongocxx::write_exception>(
bsoncxx::helpers::value_from_bson_t(gle), error);
}
If the mongo operation fails at connection level, gle is null, causing null pointer access inside value_from_bson_t(gle).
Test case:
#include <iostream> #include <mongocxx.h> using bsoncxx::builder::stream::document; using bsoncxx::builder::stream::finalize; int main() { mongocxx::instance inst; try { mongocxx::uri mongo_uri{ "mongodb://non-existent-host/" }; mongocxx::client client{ mongo_uri }; client.database("irrelevant")["irrelevant"].find_one_and_update( document{} << "irrelevant" << 1 << finalize, document{} << "irrelevant" << 2 << finalize); std::cout << "OK" << std::endl; } catch (const std::exception& ex) { std::cerr << "Exception: " << ex.what() << std::endl; } }
- is duplicated by
-
CXX-1138 uncought exception: find_and_update => precondition failed: bson
- Closed