• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #![no_main]
6 
7 use cros_fuzz::fuzz_target;
8 use vm_memory::{GuestAddress, GuestMemory};
9 
10 use std::fs::File;
11 use std::io::Write;
12 
13 const MEM_SIZE: u64 = 256 * 1024 * 1024;
14 
make_elf_bin(elf_bytes: &[u8]) -> File15 fn make_elf_bin(elf_bytes: &[u8]) -> File {
16     let mut elf_bin = tempfile::tempfile().expect("failed to create tempfile");
17     elf_bin
18         .write_all(elf_bytes)
19         .expect("failed to write elf to tempfile");
20     elf_bin
21 }
22 
23 fuzz_target!(|bytes| {
24     let mut kimage = make_elf_bin(bytes);
25     let mem = GuestMemory::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap();
26     let _ = kernel_loader::load_kernel(&mem, GuestAddress(0), &mut kimage);
27 });
28