[SERVER-56388] Coverity analysis defect 119895: _collection not initialized in default constructor Created: 27/Apr/21  Updated: 29/Oct/23  Resolved: 19/May/21

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Sebastien Mendez
Resolution: Fixed Votes: 0
Labels: coverity, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query Execution 2021-05-31
Participants:

 Description   

This is the declaration of the RestoreContext class. Note that if the default constructor is selected, _collection will be permanently uninitialized garbage because it's const. The default constructor should probably be deleted instead as the intention appears to be to use one of the constructors that provides a collection pointer.

class RestoreContext {
public:
    enum class RestoreType {
        kExternal,  // Restore on the PlanExecutor by an external call
        kYield      // Internal restore after yield
    };
 
    RestoreContext() = default;  // <--- should be deleted
    /* implicit */ RestoreContext(const CollectionPtr* coll) : _collection(coll) {}
    /* implicit */ RestoreContext(RestoreType type, const CollectionPtr* coll)
        : _type(type), _collection(coll) {}
 
    RestoreType type() const {
        return _type;
    }
    const CollectionPtr* collection() const {
        return _collection;
    }
 
private:
    RestoreType _type = RestoreType::kExternal;
    const CollectionPtr* _collection;
};

Uninitialized pointer field

The pointer field will point to an arbitrary memory location, any attempt to write may cause corruption. A pointer field is not initialized in the constructor
/src/mongo/db/query/restore_context.h:62: UNINIT_CTOR 119895 The compiler-generated constructor for this class does not initialize "_collection".



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 19/May/21 ]

Author:

{'name': 'Sebastien Mendez', 'email': 'sebastien.mendez@mongodb.com'}

Message: SERVER-56388 Remove default RestoreType constructor
Branch: master
https://github.com/mongodb/mongo/commit/049142ab3b4e9efdcf6f881fa007f1ef98304188

Generated at Thu Feb 08 05:39:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.