[CXX-1426] Check cursor pointers before to use them Created: 24/Aug/17  Updated: 28/Oct/23  Resolved: 28/Sep/17

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: legacy-1.1.2
Fix Version/s: legacy-1.1.3

Type: Bug Priority: Critical - P2
Reporter: Danilo Treffiletti Assignee: Matt Broadstone
Resolution: Fixed Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux 64 bit



 Description   

When the DBClientWithCommands::_legacyCollectionInfo method is used, if the query method return a nullptr, it will be used without any check.

Same happens also in the DBClientBase::aggregate when talking with a 2.4 server.



 Comments   
Comment by Derick Rethans [ 28/Sep/17 ]

Merged to GIT on August 24th: https://github.com/mongodb/mongo-cxx-driver/commit/01492c0699aa78f0251d9ecadcbf660d7d3b8980

Comment by Andrew Morrow (Inactive) [ 20/Sep/17 ]

dtreffiletti - As you probably noticed, I've merged this fix. Thanks for your patience while we got that moved forward. I feel obliged however to follow up and urgently suggest that migrate to the new C++11 driver, mongocxx, as soon as you possibly can.

Comment by Githook User [ 20/Sep/17 ]

Author:

{'email': 'dtreffiletti@minervanetworks.com', 'name': 'Danilo Treffiletti', 'username': 'Urban82'}

Message: CXX-1426 Check cursor pointers before to use them

Some check where missing from the commit:
CXX-229 check cursor pointers before internally iterating

Signed-off-by: Andrew Morrow <acm@mongodb.com>
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/01492c0699aa78f0251d9ecadcbf660d7d3b8980

Comment by Matt Broadstone [ 20/Sep/17 ]

acm Yes

Comment by Andrew Morrow (Inactive) [ 10/Sep/17 ]

dtreffiletti - No news yet but I in tend to take a closer look this week.

Comment by Danilo Treffiletti [ 08/Sep/17 ]

acm do you have some news about that bug?

Comment by Danilo Treffiletti [ 24/Aug/17 ]

acm the query method returns a null pointer when, for example, there are some connection issues or the server is heavily overloaded.

In other parts that involve query method, there is always the check for the null cursor.

You can verify it with the following snippet (without any type of error control):

    mongo::client::Options options;
    options.setCallShutdownAtExit(true);
    mongo::client::initialize(options);
    auto connection = new mongo::DBClientConnection(true, nullptr, 5); // Set 5 seconds timeout
    connection->connect(host_and_port);
 
    for(;;)
    {
        try
        {
            std::cout << (connection->exists(ns) ? "Y" : "N") << std::endl;
        }
        catch(std::exception& e)
        {
            std::cerr << e.what() << std::endl;
        }
    }

while code is running you can try to send SIGSTOP to the server mongod. It doesn't happen every time, but if you try to send SIGSTOP and SIGCONT, it will happen.

Comment by Andrew Morrow (Inactive) [ 24/Aug/17 ]

Thanks dtreffiletti for the bug report and PR. Under what circumstances do you find that the query method returns NULL?

Comment by Danilo Treffiletti [ 24/Aug/17 ]

Patch is proposed in https://github.com/mongodb/mongo-cxx-driver/pull/588

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