提交 06a4911c 编写于 作者: R Ralf Jung

run-time validation: accept undef in int arrays, as we do for ints

上级 b2ddd27c
...@@ -846,7 +846,7 @@ pub fn check_bytes( ...@@ -846,7 +846,7 @@ pub fn check_bytes(
&self, &self,
ptr: Scalar<M::PointerTag>, ptr: Scalar<M::PointerTag>,
size: Size, size: Size,
allow_ptr: bool, allow_ptr_and_undef: bool,
) -> EvalResult<'tcx> { ) -> EvalResult<'tcx> {
// Empty accesses don't need to be valid pointers, but they should still be non-NULL // Empty accesses don't need to be valid pointers, but they should still be non-NULL
let align = Align::from_bytes(1, 1).unwrap(); let align = Align::from_bytes(1, 1).unwrap();
...@@ -857,9 +857,9 @@ pub fn check_bytes( ...@@ -857,9 +857,9 @@ pub fn check_bytes(
let ptr = ptr.to_ptr()?; let ptr = ptr.to_ptr()?;
// Check bounds, align and relocations on the edges // Check bounds, align and relocations on the edges
self.get_bytes_with_undef_and_ptr(ptr, size, align)?; self.get_bytes_with_undef_and_ptr(ptr, size, align)?;
// Check undef, and maybe ptr // Check undef and ptr
self.check_defined(ptr, size)?; if !allow_ptr_and_undef {
if !allow_ptr { self.check_defined(ptr, size)?;
self.check_relocations(ptr, size)?; self.check_relocations(ptr, size)?;
} }
Ok(()) Ok(())
......
...@@ -517,7 +517,12 @@ pub fn validate_operand( ...@@ -517,7 +517,12 @@ pub fn validate_operand(
// reject it. However, that's good: We don't inherently want // reject it. However, that's good: We don't inherently want
// to reject those pointers, we just do not have the machinery to // to reject those pointers, we just do not have the machinery to
// talk about parts of a pointer. // talk about parts of a pointer.
match self.memory.check_bytes(dest.ptr, size, /*allow_ptr*/!const_mode) { // We also accept undef, for consistency with the type-based checks.
match self.memory.check_bytes(
dest.ptr,
size,
/*allow_ptr_and_undef*/!const_mode,
) {
// In the happy case, we needn't check anything else. // In the happy case, we needn't check anything else.
Ok(()) => {}, Ok(()) => {},
// Some error happened, try to provide a more detailed description. // Some error happened, try to provide a more detailed description.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册