[SERVER-9763] Remove BSONObjBuilder::append(const StringData&, unsigned) Created: 23/May/13  Updated: 03/Jul/19  Resolved: 03/Jul/19

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 2.5.0
Fix Version/s: 4.3.1

Type: Improvement Priority: Minor - P4
Reporter: J Rassi Assignee: Alya Berciu
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Dev Tools 2019-06-17, Dev Tools 2019-07-01, Dev Tools 2019-07-15
Participants:

 Description   

See its current implementation:

/** Append a 32 bit unsigned element - cast to a signed int. */
BSONObjBuilder& append(const StringData& fieldName, unsigned n) {
    return append(fieldName, (int) n);
}

As there does not exist a BSON encoding for unsigned integers, this method should not exist. Its existence allows for client code to mistakenly attempt to encode values between INT_MAX and UINT_MAX (to later be read off of the wire by the receiver as negative) with no compiler warnings. To illustrate:

DBClientConnection conn;
string errmsg;
conn.connect(string("127.0.0.1:27017"), errmsg);
unsigned i = UINT_MAX;
conn.insert("test.foo", BSON("data" << i));
 
> db.foo.find()
{ "_id" : ObjectId("519daf41dc3da869f5a01d17"), "data" : -1 }



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

Author:

{'name': 'Alya Berciu', 'email': 'alya.berciu@mongodb.com', 'username': 'alyacb'}

Message: SERVER-9763 Remove BSONObjBuilder append unsigned method
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/5ade901fef94f245be6780ec04c3b0b4af1442a5

Comment by Githook User [ 03/Jul/19 ]

Author:

{'name': 'Alya Berciu', 'username': 'alyacb', 'email': 'alya.berciu@mongodb.com'}

Message: SERVER-9763 Remove BSONObjBuilder append unsigned method
Branch: master
https://github.com/mongodb/mongo/commit/990b2ef30d7b8fa4db6af6d79da80e3664df9c21

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