check that ptr is valid already when doing Deref, not only when doing the access

This commit is contained in:
Ralf Jung 2019-07-27 11:02:52 +02:00
parent 9a239ef4de
commit 3b229f1441

View file

@ -304,7 +304,16 @@ where
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
let val = self.read_immediate(src)?;
trace!("deref to {} on {:?}", val.layout.ty, *val);
self.ref_to_mplace(val)
let mut place = self.ref_to_mplace(val)?;
let (size, align) = self.size_and_align_of_mplace(place)?
.unwrap_or((place.layout.size, place.layout.align.abi));
assert!(place.mplace.align <= align, "dynamic alignment less strict than static one?");
place.mplace.align = align; // maximally strict checking
// When dereferencing a pointer, it must be non-NULL, aligned, and live.
if let Some(ptr) = self.check_mplace_access(place, Some(size))? {
place.mplace.ptr = ptr.into();
}
Ok(place)
}
/// Check if the given place is good for memory access with the given