2022-09-13 17:55:17 +00:00
|
|
|
// Copyright 2019 The ChromiumOS Authors
|
2019-03-13 21:21:44 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2023-01-13 18:09:44 +00:00
|
|
|
#![cfg(not(test))]
|
2019-03-13 21:21:44 +00:00
|
|
|
#![no_main]
|
|
|
|
|
2019-06-05 16:52:13 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
2022-10-03 19:08:17 +00:00
|
|
|
|
|
|
|
use cros_fuzz::fuzz_target;
|
2022-07-27 18:11:32 +00:00
|
|
|
use vm_memory::GuestAddress;
|
|
|
|
use vm_memory::GuestMemory;
|
|
|
|
|
2019-06-05 17:19:02 +00:00
|
|
|
const MEM_SIZE: u64 = 256 * 1024 * 1024;
|
|
|
|
|
2019-06-05 16:52:13 +00:00
|
|
|
fn make_elf_bin(elf_bytes: &[u8]) -> File {
|
2020-10-09 21:08:27 +00:00
|
|
|
let mut elf_bin = tempfile::tempfile().expect("failed to create tempfile");
|
|
|
|
elf_bin
|
|
|
|
.write_all(elf_bytes)
|
|
|
|
.expect("failed to write elf to tempfile");
|
|
|
|
elf_bin
|
2019-06-05 16:52:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 17:25:16 +00:00
|
|
|
fuzz_target!(|bytes| {
|
|
|
|
let mut kimage = make_elf_bin(bytes);
|
|
|
|
let mem = GuestMemory::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap();
|
2022-11-18 22:36:40 +00:00
|
|
|
let _ = kernel_loader::load_elf32(&mem, GuestAddress(0), &mut kimage, 0);
|
|
|
|
let _ = kernel_loader::load_elf64(&mem, GuestAddress(0), &mut kimage, 0);
|
2019-10-24 17:25:16 +00:00
|
|
|
});
|