Skip to content

Commit 46f7ccc

Browse files
committed
gen_random: use check_ptr_access
1 parent e56728b commit 46f7ccc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/helpers.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::mem;
22

3-
use rustc::ty::{self, layout::{self, Size}};
3+
use rustc::ty::{self, layout::{self, Size, Align}};
44
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
55

66
use rand::RngCore;
@@ -49,14 +49,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4949
fn gen_random(
5050
&mut self,
5151
len: usize,
52-
dest: Scalar<Tag>,
52+
ptr: Scalar<Tag>,
5353
) -> InterpResult<'tcx> {
54-
if len == 0 {
55-
// Nothing to do
56-
return Ok(());
57-
}
5854
let this = self.eval_context_mut();
59-
let ptr = dest.to_ptr()?;
55+
56+
let ptr = match this.memory().check_ptr_access(ptr, Size::from_bytes(len as u64), Align::from_bytes(1).unwrap())? {
57+
Some(ptr) => ptr,
58+
None => return Ok(()), // zero-sized access
59+
};
6060

6161
let data = match &mut this.memory_mut().extra.rng {
6262
Some(rng) => {

0 commit comments

Comments
 (0)