mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
a6e7d6f139
Adds a fall-back to cros_fuzz when compiled without fuzzing enabled that will just produce a main fn entrypoint with the fuzzing code. This allows the fuzzing code to be compiled, but won't produce functional fuzzing binaries. BUG=b:265829867 FIXES=b:244631591 TEST=crosvm CQ cargo +nightly fuzz run --fuzz-dir crosvm-fuzz --features upstream-fuzz crosvm_block_fuzzer Change-Id: Ib2602aab5c5373cb2a71dca0d8419640a00c6725 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4167143 Commit-Queue: Dennis Kempin <denniskempin@google.com> Reviewed-by: Zihan Chen <zihanchen@google.com>
30 lines
877 B
Rust
30 lines
877 B
Rust
// Copyright 2019 The ChromiumOS Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#![cfg(not(test))]
|
|
#![no_main]
|
|
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
|
|
use cros_fuzz::fuzz_target;
|
|
use vm_memory::GuestAddress;
|
|
use vm_memory::GuestMemory;
|
|
|
|
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_elf32(&mem, GuestAddress(0), &mut kimage, 0);
|
|
let _ = kernel_loader::load_elf64(&mem, GuestAddress(0), &mut kimage, 0);
|
|
});
|