Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/fuzz/fuzz_targets/zimage_fuzzer.rs
5394 views
1
// Copyright 2019 The ChromiumOS Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#![cfg(not(test))]
6
#![no_main]
7
8
use std::fs::File;
9
use std::io::Write;
10
11
use crosvm_fuzz::fuzz_target;
12
use vm_memory::GuestAddress;
13
use vm_memory::GuestMemory;
14
15
const MEM_SIZE: u64 = 256 * 1024 * 1024;
16
17
fn make_elf_bin(elf_bytes: &[u8]) -> File {
18
let mut elf_bin = tempfile::tempfile().expect("failed to create tempfile");
19
elf_bin
20
.write_all(elf_bytes)
21
.expect("failed to write elf to tempfile");
22
elf_bin
23
}
24
25
fuzz_target!(|bytes| {
26
let mut kimage = make_elf_bin(bytes);
27
let mem = GuestMemory::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap();
28
let _ = kernel_loader::load_elf(&mem, GuestAddress(0), &mut kimage, 0);
29
});
30
31