Skip to content

Commit

Permalink
Add random memory writes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Mar 14, 2024
1 parent 910d759 commit 4b3a5eb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions fuzz/fuzz_targets/snapshot2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ impl DataSource<u32> for DummyData {
let data = match *id {
DATA_SOURCE_PROGRAM => &self.program,
DATA_SOURCE_CONTENT => &self.content,
_ => {
panic!("invalid id")
}
_ => unreachable!(),
};
Ok((
data.slice(offset as usize..offset as usize + length as usize),
Expand Down Expand Up @@ -91,7 +89,7 @@ fuzz_target!(|data: [u8; 32]| {
let mut loading_action_vec: Vec<LoadingAction> = Vec::new();
for i in 0..2 + deque.u8() as usize % 3 {
let segsize = deque.u16() as u64 % 1024;
let p_vaddr = i as u64 * 1024 * 1024;
let p_vaddr = i as u64 * 1024 * 256;
let p_memsz = segsize;
let p_offset = deque.u32() as u64 % (dummy_data.program.len() as u64 - segsize);
let p_filesz = segsize;
Expand Down Expand Up @@ -121,6 +119,19 @@ fuzz_target!(|data: [u8; 32]| {
.load_program_with_metadata(&dummy_data.program, &metadata, &vec![])
.unwrap();
ctx.mark_program(&mut machine1, &metadata, &0, 0).unwrap();
for i in 0..2 + deque.u8() as usize % 3 {
let id = i as u32 % 2;
let data = match id {
DATA_SOURCE_PROGRAM => &dummy_data.program,
DATA_SOURCE_CONTENT => &dummy_data.content,
_ => unreachable!(),
};
let length = deque.u16() as u64 % 1024;
let offset = deque.u32() as u64 % (data.len() as u64 - length);
let addr = 1024 * 1024 + (deque.u8() as u64 % 4) * 1024 * 256;
ctx.store_bytes(&mut machine1, addr, &id, offset, length)
.unwrap();
}
let snapshot = ctx.make_snapshot(&mut machine1).unwrap();
ctx.resume(&mut machine2, &snapshot).unwrap();
let mem1 = machine1
Expand Down

0 comments on commit 4b3a5eb

Please sign in to comment.