• 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 tempfile;
9 use vm_memory::{GuestAddress, GuestMemory};
10 
11 use std::fs::File;
12 use std::io::Write;
13 
14 const MEM_SIZE: u64 = 256 * 1024 * 1024;
15 
make_elf_bin(elf_bytes: &[u8]) -> File16 fn make_elf_bin(elf_bytes: &[u8]) -> File {
17     let mut elf_bin = tempfile::tempfile().expect("failed to create tempfile");
18     elf_bin
19         .write_all(elf_bytes)
20         .expect("failed to write elf to tempfile");
21     elf_bin
22 }
23 
24 fuzz_target!(|bytes| {
25     let mut kimage = make_elf_bin(bytes);
26     let mem = GuestMemory::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap();
27     let _ = kernel_loader::load_kernel(&mem, GuestAddress(0), &mut kimage);
28 });
29