[SERVER-14936] Remove undefined behavior around BSONObj::Holder Created: 18/Aug/14  Updated: 08/Sep/14  Resolved: 19/Aug/14

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 2.7.6

Type: Improvement Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Participants:

 Description   

Currently, we assume that by reserving four bytes at the beginning of a buffer, we are permitted to re-interpret cast that region of memory to a BSONObj::Holder.

In fact, it is only legal to reinterpret_cast a region of memory to a class type if the memory originally held a properly constructed object of that type.

An additional problem is that the region of memory owned by the BSONObjBuilder may be realloc'ed. We cannot place a class at the beginning of the region and assume that it will survive realloc.

Instead, we should refactor the relationship between BSONObjBuilder and BSONObj so that the builder reserves but does not initialize a prefix region of appropriate size and alignment to hold a BSONObj::Holder, and then BSONObj placement new's a Holder into that region when it takes ownership of the buffer.



 Comments   
Comment by Githook User [ 19/Aug/14 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: SERVER-14936 Give BSONObj::Holder a proper class lifecycle
Branch: master
https://github.com/mongodb/mongo/commit/6354bcfdd21c632c7578745bd4b794aaf16b491a

Generated at Thu Feb 08 03:36:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.