Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@achabense
Copy link
Contributor

@achabense achabense commented Aug 12, 2023

Fixes #3955 / VSO-1854254 / AB#1854254 (fix string's self-assignment with offset via pointers under ASan)
Fixes VSO-1854245 / AB#1854245 "ASan issue in basic_string::assign(pointer)"
Fixes VSO-1854251 / AB#1854251 "ASan issue in basic_string::assign(iterator, iterator)"
Fixes VSO-1854242 / AB#1854242 "ASan issue in tests/std/P0980R1_constexpr_strings [basic_string::resize_and_overwrite]"

Drive-by: In resize_and_overwrite, compare the converted result size so we need not suppress the "comparing signed and unsigned" warning.

Test coverage for the latter three fixes will be in the ASan test coverage that's incoming in the near future.

@achabense achabense requested a review from a team as a code owner August 12, 2023 16:39
@StephanTLavavej StephanTLavavej added bug Something isn't working ASan Address Sanitizer labels Aug 13, 2023
@StephanTLavavej StephanTLavavej self-assigned this Aug 14, 2023
Copy link
Contributor

@strega-nil-ms strega-nil-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing my mistake -.-

The argument may alias `*this`, so don't shrink until after we copy the characters.
We need to update the buffer info even if we do not allocate.
Compare the converted "result size" to the "new size" so we don't need to suppress C4108. Improves readability and throughput a teeny bit.
@CaseyCarter CaseyCarter changed the title Fix string::assign under ASan Fix string::assign and ::resize_and_overwrite under ASan Aug 15, 2023
@StephanTLavavej StephanTLavavej removed their assignment Aug 16, 2023
@achabense
Copy link
Contributor Author

achabense commented Aug 16, 2023

Sorry for my oversight😿 I've add a test for the problem introduced by my "fix".

@StephanTLavavej StephanTLavavej self-assigned this Aug 17, 2023
@StephanTLavavej
Copy link
Member

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

@StephanTLavavej StephanTLavavej merged commit 21eca6f into microsoft:main Aug 18, 2023
@StephanTLavavej
Copy link
Member

Thanks for fixing these bugs in one of the STL's most popular types and one of MSVC's most important new features! 😻 🐞 🛠️

@achabense achabense deleted the _GH3955fix branch August 21, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASan Address Sanitizer bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<xstring>: ASAN report container-overflow in a legal case

6 participants