Skip to content

added a strings.rs regression test case for potential future UB#1824

Merged
bors merged 1 commit intorust-lang:masterfrom
Pointerbender:strings-test
Jun 3, 2021
Merged

added a strings.rs regression test case for potential future UB#1824
bors merged 1 commit intorust-lang:masterfrom
Pointerbender:strings-test

Conversation

@Pointerbender
Copy link
Copy Markdown
Contributor

This PR adds a regression test for the aliasing rules of a Unique<T> pointer.
At the time of writing this test case, Miri does not treat Unique<T>
pointers as a special case, these are treated like any other raw pointer.
However, there are existing Github issues which may lead to Unique<T>
becoming a special case through asserting unique ownership over the pointee:
- rust-lang/unsafe-code-guidelines#258
- rust-lang/unsafe-code-guidelines#262
In the new test case, the calls to String::remove and String::insert[_str] follow
code paths that would trigger undefined behavior in case Unique<T>
would ever assert semantic ownership over the pointee. Internally,
these methods call self.vec.as_ptr() and self.vec.as_mut_ptr() on
the vector of bytes that are backing the String. That Vec<u8> holds a
Unique<u8> internally. The second call to Vec::as_mut_ptr(&mut self)
would then invalidate the pointers derived from Vec::as_ptr(&self).
Note that as long as Unique<T> is treated like any other raw pointer,
this test case should pass. It is merely here as a canary test for
potential future undefined behavior.

@RalfJung
Copy link
Copy Markdown
Member

RalfJung commented Jun 3, 2021

Looking good, thanks. :-)
@bors r+

@bors
Copy link
Copy Markdown
Contributor

bors commented Jun 3, 2021

📌 Commit 386863a has been approved by RalfJung

@bors
Copy link
Copy Markdown
Contributor

bors commented Jun 3, 2021

⌛ Testing commit 386863a with merge 44122f9...

@bors
Copy link
Copy Markdown
Contributor

bors commented Jun 3, 2021

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 44122f9 to master...

@bors bors merged commit 44122f9 into rust-lang:master Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants