[SERVER-78676] Replace c-string constructor with fill constructor in CurrentOpExhaustCursorTestFixture::initTestCollection on v5.0 Created: 05/Jul/23  Updated: 29/Oct/23  Resolved: 31/Jul/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.4.24, 5.0.20

Type: Bug Priority: Major - P3
Reporter: Davis Haupt (Inactive) Assignee: Davis Haupt (Inactive)
Resolution: Fixed Votes: 0
Labels: greenerbuild
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Assigned Teams:
Query Integration
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.4
Sprint: QI 2023-07-10, QI 2023-07-24, QI 2023-08-07
Participants:
Linked BF Score: 51

 Description   

We're creating a std::string of a certain large size, but only initializing it with a string of size 1 here. From the std::string constructor docs, it looks like instead of std::string("A", size), we should use std::string(size, "A") to fill the string with the string "A" repeated.

Note that this code doesn't exist on versions after 5.0, and so will only need to change on v5.0 and v4.4.
 



 Comments   
Comment by Githook User [ 10/Aug/23 ]

Author:

{'name': 'Davis Haupt', 'email': 'davis.haupt@mongodb.com', 'username': 'davish'}

Message: SERVER-78676 Replace c-string constructor with fill constructor in CurrentOpExhaustCursorTestFixture::initTestCollection

Using the constructor std::string(char*, size_t) was causing a buffer overflow when the string was not as long as the size passed in.
in order to fill up the string with a character repeatedly, the proper constructor is std::string(size_t, char).
Branch: v4.4
https://github.com/mongodb/mongo/commit/12e50b83e443a6df3eda92025a467d5c2dd99084

Comment by Githook User [ 31/Jul/23 ]

Author:

{'name': 'Davis Haupt', 'email': 'davis.haupt@mongodb.com', 'username': 'davish'}

Message: SERVER-78676 Replace c-string constructor with fill constructor in CurrentOpExhaustCursorTestFixture::initTestCollection

Using the constructor std::string(char*, size_t) was causing a buffer overflow when the string was not as long as the size passed in.
in order to fill up the string with a character repeatedly, the proper constructor is std::string(size_t, char).
Branch: v5.0
https://github.com/mongodb/mongo/commit/6eef640382d3259273b532a7bf2cd744b232d086

Generated at Thu Feb 08 06:38:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.