[SERVER-47357] `fmt::formatter<HostAndPort>::format` returns wrong iterator Created: 06/Apr/20  Updated: 29/Oct/23  Resolved: 07/Apr/20

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.4.0-rc0, 4.7.0

Type: Bug Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.4
Sprint: Service arch 2020-04-20
Participants:

 Description   

`fmt::formatter::format` writes into and advances an output iterator obtained by `ctx.out()`.  It has to return the advanced output iterator. But we return the `ctx.out()`, not the copy we advanced.

This yielded UB in a toolchain validation build against mongo 4.2 on
“Amazon Linux 1 2018.03" the build image.

[https://logkeeper.mongodb.org/lobster/build/24a6f9b5ad70e8fbfc9bed6e0ccf388e/test/5e8a1e02be07c446740c1d7f#bookmarks=0%2C19%2C67

]
 

[cpp_unit_test:network_test] 2020-04-05T18:05:54.634+0000 2020-04-05T18:05:54.634+0000 E - [main] Throwing exception: Expected fmt::format("{}", hp) == hps (1.2.3.4:2\0\0\0\0 == 1.2.3.4:27017) @src/mongo/util/net/hostandport_test.cpp:139

[cpp_unit_test:network_test] 2020-04-05T18:05:54.634+0000 2020-04-05T18:05:54.634+0000 I - [main] FAIL: Fmt Expected fmt::format("{}", hp) == hps (1.2.3.4:2\0\0\0\0 == 1.2.3.4:27017) @src/mongo/util/net/hostandport_test.cpp:139 in test Fmt  

 
 

 



 Comments   
Comment by Billy Donahue [ 07/Apr/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Date: Mon Apr 6 12:53:35 2020 -0400

Message: SERVER-47357 return incremented iterator from fmt::formatter<HostAndPort>
Branch: v4.4
https://github.com/mongodb/mongo/commit/472f531dc30b447eabf505fee8f9603d5001b98c

 

Comment by Githook User [ 07/Apr/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-47357 return incremented iterator from fmt::formatter<HostAndPort>
Branch: master
https://github.com/mongodb/mongo/commit/d329a6737b6305814f646c9bc37c9393b8254c30

Comment by Billy Donahue [ 06/Apr/20 ]

discovered while upgrading toolchain in BUILD-10181

Comment by Billy Donahue [ 06/Apr/20 ]

http://mongodbcr.appspot.com/561330010

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