Skip to content

Properly null-terminate output buffer in basic_istream::get[line] - #5073

Merged
Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:mainfrom
muellerj2:istream-get-nulltermination
Nov 14, 2024
Merged

Properly null-terminate output buffer in basic_istream::get[line]#5073
Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:mainfrom
muellerj2:istream-get-nulltermination

Conversation

@muellerj2

Copy link
Copy Markdown

Fixes #5070.

The libcxx tests istream.unformatted/get_pointer_size.pass.cpp and get_pointer_size_chart.pass.cpp pass now.

Since this issue is mostly about correct null-termination in the presence of exceptions, I added the tests to GH_001858_iostream_exception. They should cover the relevant cases:

  • output buffer of size zero with and without exception on failbit
  • sentry failure with and without exception on failbit
  • exception during streambuf character extraction with and without badbit exception propagation
  • encountering EOF with and without exception on eofbit

@muellerj2
Julian Müller (muellerj2) requested a review from a team as a code owner November 10, 2024 20:29
@muellerj2

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Comment thread stl/inc/istream Outdated
Comment thread stl/inc/istream Outdated
Comment thread tests/std/tests/GH_001858_iostream_exception/test.cpp
Comment thread tests/std/tests/GH_001858_iostream_exception/test.cpp Outdated
Comment thread tests/std/tests/GH_001858_iostream_exception/test.cpp Outdated
Comment thread tests/std/tests/GH_001858_iostream_exception/test.cpp Outdated
Comment thread tests/std/tests/GH_001858_iostream_exception/test.cpp
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks, this is fantastic - and incredible for a first PR! 😻 I've pushed several minor nitpicks, a product code simplification, and a test code improvement. I appreciate the extremely detailed test coverage.

We merge PRs simultaneously to our GitHub and MSVC-internal repos, mirrored in a semi-manual process and batched up to save time. Your PR will be part of the next batch, very likely this week.

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit ca1af94 into microsoft:main Nov 14, 2024
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks again, and congratulations on your first microsoft/STL commit! 🚀 😸 🥳

This change is expected to ship in VS 2022 17.13 Preview 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<istream>: basic_istream::get[line](char_type* s, std::streamsize n, char_type delim) do not null-terminate the output buffer correctly

3 participants