about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-07-27 11:02:52 +0200
committerRalf Jung <post@ralfj.de>2019-07-28 10:19:57 +0200
commit3b229f144160067409dd9d321748ab7ae77bd99c (patch)
tree4c0bd1ea0f9effa11d2dd6b0b2be270e68ca39ab
parent9a239ef4ded03d155c72b68b5a2dd7aff013e141 (diff)
downloadrust-3b229f144160067409dd9d321748ab7ae77bd99c.tar.gz
rust-3b229f144160067409dd9d321748ab7ae77bd99c.zip
check that ptr is valid already when doing Deref, not only when doing the access
-rw-r--r--src/librustc_mir/interpret/place.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs
index 8fe882934df..e90fc28a521 100644
--- a/src/librustc_mir/interpret/place.rs
+++ b/src/librustc_mir/interpret/place.rs
@@ -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