crosvm/crosvm-fuzz/zimage_fuzzer.rs
Dennis Kempin 8a1c50d5cd Refactoring: Move various general purpose crates to common/
This change contains the results of running

./tools/contib/cargo_refactor.py

This will break the next uprev, and needs to be synchronizized
with the corresponding ebuild changes in https://crrev.com/c/3248925

BUG=b:195126527
TEST=./tools/run_tests

Change-Id: Ied15a1841887bb8f59fba65b912b81acf69beb73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3248129
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-29 22:31:43 +00:00

29 lines
802 B
Rust

// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#![no_main]
use cros_fuzz::fuzz_target;
use tempfile;
use vm_memory::{GuestAddress, GuestMemory};
use std::fs::File;
use std::io::Write;
const MEM_SIZE: u64 = 256 * 1024 * 1024;
fn make_elf_bin(elf_bytes: &[u8]) -> File {
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
}
fuzz_target!(|bytes| {
let mut kimage = make_elf_bin(bytes);
let mem = GuestMemory::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap();
let _ = kernel_loader::load_kernel(&mem, GuestAddress(0), &mut kimage);
});