1
Fork 0

Rollup merge of #70479 - RalfJung:win-env, r=Mark-Simulacrum

avoid creating unnecessary reference in Windows Env iterator

Discovered in https://github.com/rust-lang/miri/pull/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 https://github.com/rust-lang/unsafe-code-guidelines/issues/134
This commit is contained in:
Dylan DPC 2020-03-30 16:24:44 +02:00 committed by GitHub
commit 47ffca296a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;