Skip to content

Commit

Permalink
Merge pull request #162 from p4zuu/insn_decoder_fuzzing
Browse files Browse the repository at this point in the history
fuzz: add x86 instructions decoder harness
  • Loading branch information
joergroedel authored Nov 27, 2023
2 parents 5adfa49 + 3fbe0e2 commit 881daa2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ name = "alloc"
path = "fuzz_targets/alloc.rs"
test = false
doc = false

[[bin]]
name = "insn"
path = "fuzz_targets/insn.rs"
test = false
doc = false
18 changes: 18 additions & 0 deletions fuzz/fuzz_targets/insn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![no_main]

use libfuzzer_sys::{fuzz_target, Corpus};
use svsm::cpu::insn::{Instruction, MAX_INSN_SIZE};

fuzz_target!(|input: &[u8]| -> Corpus {
let Some(input) = input.get(..MAX_INSN_SIZE) else {
return Corpus::Reject;
};

let mut data = [0u8; MAX_INSN_SIZE];
data.copy_from_slice(input);

let mut insn = Instruction::new(data);
let _ = core::hint::black_box(insn.decode());

Corpus::Keep
});

0 comments on commit 881daa2

Please sign in to comment.