Skip to content

Commit

Permalink
wast: Fix pointer provenance bug reported by MIRI
Browse files Browse the repository at this point in the history
We need to re-derive the str pointer after moving the original `Box<str>` it was
derived from.
  • Loading branch information
fitzgen committed Jan 26, 2024
1 parent a6160b3 commit fa9fa87
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/wast/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ impl ParseBuffer<'_> {
/// This will return a reference to `s`, but one that's safely rooted in the
/// `Parser`.
fn push_str(&self, s: Vec<u8>) -> &[u8] {
let s = Box::from(s);
let ret = &*s as *const [u8];
self.strings.borrow_mut().push(s);
let mut strings = self.strings.borrow_mut();
strings.push(Box::from(s));
let ret = &**strings.last().unwrap() as *const [u8];
// This should be safe in that the address of `ret` isn't changing as
// it's on the heap itself. Additionally the lifetime of this return
// value is tied to the lifetime of `self` (nothing is deallocated
Expand Down

0 comments on commit fa9fa87

Please sign in to comment.