[SERVER-41989] BSONObjBuilder::asTempObj is not exception safe Created: 27/Jun/19  Updated: 29/Oct/23  Resolved: 26/Jul/19

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 3.6.13, 4.0.10, 4.2.0-rc2
Fix Version/s: 4.3.1

Type: Bug Priority: Major - P3
Reporter: Matthew Saltz (Inactive) Assignee: ADAM Martin (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Gantt Dependency
has to be done before SERVER-42034 Remove numStr from BSONObjBuilder Closed
has to be done after SERVER-42313 Fix forwarding reference issue in `Sc... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.2, v4.0, v3.6
Sprint: Dev Tools 2019-07-15, Dev Tools 2019-07-29
Participants:
Case:

 Description   

If this line throws, e.g. due to the object we're trying to construct being too large, this leaves the BSONObjBuilder in a state where "_doneCalled" is true, which can later lead to this invariant being hit unexpectedly. We should either make this function exception-safe and reset the state of the BSONObjBuilder to how it was before calling _done() in this line, if possible, and if not, we should update callers to be prepared for the possibility of this throwing.



 Comments   
Comment by Githook User [ 26/Jul/19 ]

Author:

{'name': 'ADAM David Alan Martin', 'username': 'adamlsd', 'email': 'adam.martin@10gen.com'}

Message: SERVER-41989 Fix exception safety in `BSONObjBuilder::asTempObj`.

The setting of `_doneCalled` too early allows for it to remain set
after an exception is thrown. This will cause invariant violations
under some conditions.
Branch: master
https://github.com/mongodb/mongo/commit/5090e4efc24b88d28fa83d30457e1d097f2fc273

Generated at Thu Feb 08 04:59:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.