Skip to content

Commit

Permalink
Rollup merge of rust-lang#70479 - RalfJung:win-env, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
avoid creating unnecessary reference in Windows Env iterator

Discovered in rust-lang/miri#1225: the Windows `Env` iterator violates Stacked Borrows by creating an `&u16`, turning it into a raw pointer, and then accessing memory outside the range of that type.

There is no need to create a reference here in the first place, so the fix is trivial.
Cc @JOE1994
Cc rust-lang/unsafe-code-guidelines#134
  • Loading branch information
Dylan-DPC authored Mar 30, 2020
2 parents a80ec3b + 2a1e61e commit 47ffca2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Iterator for Env {
if *self.cur == 0 {
return None;
}
let p = &*self.cur as *const u16;
let p = self.cur as *const u16;
let mut len = 0;
while *p.offset(len) != 0 {
len += 1;
Expand Down

0 comments on commit 47ffca2

Please sign in to comment.