Skip to content

Commit

Permalink
fix: fuzzer now makes short programs; fix crash in near call (#52)
Browse files Browse the repository at this point in the history
The fuzzer's random program generation was accidentally only generating
programs that have instructions everywhere. The data structure had an
Option but it was always Some.

Because of this a very simple crash in near call wasn't caught. It is
fixed here.
  • Loading branch information
joonazan authored Jul 31, 2024
1 parent 2877059 commit 985a778
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/instruction_handlers/near_call.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::ret::INVALID_INSTRUCTION;
use crate::{
addressing_modes::{Arguments, Immediate1, Immediate2, Register1, Source},
instruction::InstructionResult,
Expand Down Expand Up @@ -35,7 +36,7 @@ fn near_call(
.current_frame
.program
.instruction(destination.low_u32() as u16)
.unwrap())
.unwrap_or(&INVALID_INSTRUCTION))
}

impl Instruction {
Expand Down
8 changes: 4 additions & 4 deletions src/single_instruction_test/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl<'a> Arbitrary<'a> for Program {
decode(raw_first_instruction, false),
Instruction::from_invalid(),
])),
other_instruction: MockRead::new(Rc::new(Some([
Instruction::from_invalid(),
Instruction::from_invalid(),
]))),
other_instruction: MockRead::new(Rc::new(
u.arbitrary::<bool>()?
.then_some([Instruction::from_invalid(), Instruction::from_invalid()]),
)),
code_page: [u.arbitrary()?; 1].into(),
})
}
Expand Down

0 comments on commit 985a778

Please sign in to comment.