[SERVER-62231] Methods for iterating a DBClientCursor should assert that init() has been called Created: 22/Dec/21  Updated: 29/Oct/23  Resolved: 28/Jun/22

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

Type: Improvement Priority: Major - P3
Reporter: David Storch Assignee: Catalin Sumanaru
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-61385 Migrate most callers of legacy 'DBCli... Closed
Backwards Compatibility: Fully Compatible
Sprint: QE 2022-06-27, QE 2022-07-11
Participants:
Linked BF Score: 64

 Description   

In order to fully initialize a DBClientCursor object, one must first call its constructor and then subsequently call DBClientCursor::init(). If the programmer makes a mistake and fails to call init(), the cursor can silently return no results rather than raising an error. Consider code like this:

DBClientCursor cursor{...};
while (cursor->more()) {
    BSONObj obj = cursor->nextSafe();
    // Do something with 'obj'.
}

This code is incorrect, since it fails to call init(). However, the call to cursor->more() simply returns false rather than throwing or tripping an assertion, so the bug could easily go undetected. We should improve the code to uassert() or possibly invariant() in this scenario.



 Comments   
Comment by Githook User [ 28/Jun/22 ]

Author:

{'name': 'Catalin Sumanaru', 'email': 'catalin.sumanaru@mongodb.com'}

Message: SERVER-62231 Ensure DBClientCursor methods call init
Branch: master
https://github.com/mongodb/mongo/commit/e6b088a0991af9573d6e17b1ee9beb3fe969500d

Comment by Denis Grebennicov [ 07/Jun/22 ]

Reserved for Catalin Sumanaru as neweng intern ticket work.

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