Add Miri regression test for CString::clone_into unwind safety#158763
Closed
Vastargazing wants to merge 1 commit into
Closed
Add Miri regression test for CString::clone_into unwind safety#158763Vastargazing wants to merge 1 commit into
Vastargazing wants to merge 1 commit into
Conversation
CString::clone_into reuses the target's allocation by moving the buffer into a Vec and growing it. If that growth's allocation fails and the alloc error hook unwinds, the target has to be left as a valid CString, but nothing covered that path. Add a Miri test that fails the reallocation under a panicking alloc error hook and checks that the caught unwind leaves the target's nul terminator in place.
Collaborator
|
cc @rust-lang/miri |
Collaborator
|
|
Contributor
Please do this, your change has no rustc change requirements |
RalfJung
reviewed
Jul 4, 2026
Member
There was a problem hiding this comment.
Please reference the relevant issue(s) from the test in comments.
Also... does this have to be in the Miri test suite? We run the liballoc test suite in Miri on CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Regression test for the panic-unsoundness fixed in #155707
#70201 added a
clone_intooverride forCStrthat moved the targetCString's buffer out (leaving it empty) before growing aVec. On allocation failure, the destinationCStringcould lose its trailing nul terminator, leading to UB.#155707 fixed this but didn't add a test.
The reviewer suggested a
#[global_allocator]wrapper inlibrary/alloctestsmodeled onvec_deque_alloc_error.rs, but that doesn't reproduce the bug: library tests link std with-C prefer-dynamic, so a global allocator in the test binary doesn't intercept the reallocation insideCString::clone_into, which lives inlibstd. Under Miri it does, so this adds a Miri pass test that fails one reallocation under a panicking alloc error hook and checks that the target remains valid.r? @RalfJung