ensure that integers cast to pointers will never point at a valid alloc, not even the zst alloc
This commit is contained in:
parent
2d4301ea7e
commit
921f5af1fe
@ -61,7 +61,7 @@ impl<'tcx> Error for EvalError<'tcx> {
|
||||
EvalError::DanglingPointerDeref =>
|
||||
"dangling pointer was dereferenced",
|
||||
EvalError::InvalidFunctionPointer =>
|
||||
"tried to use a pointer as a function pointer",
|
||||
"tried to use an integer pointer as a function pointer",
|
||||
EvalError::InvalidBool =>
|
||||
"invalid boolean value read",
|
||||
EvalError::InvalidDiscriminant =>
|
||||
|
@ -639,7 +639,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||
};
|
||||
let drop_fn = self.memory.read_ptr(vtable)?;
|
||||
// some values don't need to call a drop impl, so the value is null
|
||||
if !drop_fn.points_to_zst() {
|
||||
if drop_fn != Pointer::from_int(0) {
|
||||
let (def_id, substs, ty) = self.memory.get_fn(drop_fn.alloc_id)?;
|
||||
let fn_sig = self.tcx.erase_late_bound_regions_and_normalize(&ty.sig);
|
||||
let real_ty = fn_sig.inputs[0];
|
||||
|
@ -73,7 +73,7 @@ impl Pointer {
|
||||
// FIXME(solson): Integer pointers should use u64, not usize. Target pointers can be larger
|
||||
// than host usize.
|
||||
pub fn from_int(i: usize) -> Self {
|
||||
Pointer::new(ZST_ALLOC_ID, i)
|
||||
Pointer::new(NEVER_ALLOC_ID, i)
|
||||
}
|
||||
|
||||
pub fn zst_ptr() -> Self {
|
||||
@ -290,7 +290,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||
Some(alloc) => Ok(alloc),
|
||||
None => match self.functions.get(&id) {
|
||||
Some(_) => Err(EvalError::DerefFunctionPointer),
|
||||
None if id == ZST_ALLOC_ID => Err(EvalError::InvalidMemoryAccess),
|
||||
None if id == NEVER_ALLOC_ID || id == ZST_ALLOC_ID => Err(EvalError::InvalidMemoryAccess),
|
||||
None => Err(EvalError::DanglingPointerDeref),
|
||||
}
|
||||
}
|
||||
@ -302,7 +302,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||
Some(alloc) => Ok(alloc),
|
||||
None => match self.functions.get(&id) {
|
||||
Some(_) => Err(EvalError::DerefFunctionPointer),
|
||||
None if id == ZST_ALLOC_ID => Err(EvalError::InvalidMemoryAccess),
|
||||
None if id == NEVER_ALLOC_ID || id == ZST_ALLOC_ID => Err(EvalError::InvalidMemoryAccess),
|
||||
None => Err(EvalError::DanglingPointerDeref),
|
||||
}
|
||||
}
|
||||
|
3
tests/run-pass/assume_bug.rs
Normal file
3
tests/run-pass/assume_bug.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
vec![()].into_iter();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user