Skip to content

Commit

Permalink
run-time validation: accept undef in int arrays, as we do for ints
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 13, 2018
1 parent b2ddd27 commit 06a4911
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/librustc_mir/interpret/memory.rs
Expand Up @@ -846,7 +846,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
&self,
ptr: Scalar<M::PointerTag>,
size: Size,
allow_ptr: bool,
allow_ptr_and_undef: bool,
) -> EvalResult<'tcx> {
// Empty accesses don't need to be valid pointers, but they should still be non-NULL
let align = Align::from_bytes(1, 1).unwrap();
Expand All @@ -857,9 +857,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
let ptr = ptr.to_ptr()?;
// Check bounds, align and relocations on the edges
self.get_bytes_with_undef_and_ptr(ptr, size, align)?;
// Check undef, and maybe ptr
self.check_defined(ptr, size)?;
if !allow_ptr {
// Check undef and ptr
if !allow_ptr_and_undef {
self.check_defined(ptr, size)?;
self.check_relocations(ptr, size)?;
}
Ok(())
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_mir/interpret/validity.rs
Expand Up @@ -517,7 +517,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
// reject it. However, that's good: We don't inherently want
// to reject those pointers, we just do not have the machinery to
// 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.
Ok(()) => {},
// Some error happened, try to provide a more detailed description.
Expand Down

0 comments on commit 06a4911

Please sign in to comment.