Skip to content

Commit 3b229f1

Browse files
committed
check that ptr is valid already when doing Deref, not only when doing the access
1 parent 9a239ef commit 3b229f1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/librustc_mir/interpret/place.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,16 @@ where
304304
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
305305
let val = self.read_immediate(src)?;
306306
trace!("deref to {} on {:?}", val.layout.ty, *val);
307-
self.ref_to_mplace(val)
307+
let mut place = self.ref_to_mplace(val)?;
308+
let (size, align) = self.size_and_align_of_mplace(place)?
309+
.unwrap_or((place.layout.size, place.layout.align.abi));
310+
assert!(place.mplace.align <= align, "dynamic alignment less strict than static one?");
311+
place.mplace.align = align; // maximally strict checking
312+
// When dereferencing a pointer, it must be non-NULL, aligned, and live.
313+
if let Some(ptr) = self.check_mplace_access(place, Some(size))? {
314+
place.mplace.ptr = ptr.into();
315+
}
316+
Ok(place)
308317
}
309318

310319
/// Check if the given place is good for memory access with the given

0 commit comments

Comments
 (0)