mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
fuzz: explicitly keep or reject fuzzer corpus
When the main fuzzer function returns (), it is equivalent to returning Corpus::Keep. In some of the return paths, we want to reject the input so that the libfuzzer won't spend more time mutating them. The should make fuzzing more efficient. No functional change intended. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -12,14 +12,14 @@ use std::mem::size_of;
|
||||
use std::os::unix::io::{FromRawFd, RawFd};
|
||||
|
||||
use block::qcow::{QcowFile, RawFile};
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use libfuzzer_sys::{fuzz_target, Corpus};
|
||||
|
||||
// Take the first 64 bits of data as an address and the next 64 bits as data to
|
||||
// store there. The rest of the data is used as a qcow image.
|
||||
fuzz_target!(|bytes| {
|
||||
fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
if bytes.len() < 16 {
|
||||
// Need an address and data, each are 8 bytes.
|
||||
return;
|
||||
return Corpus::Reject;
|
||||
}
|
||||
let mut disk_image = Cursor::new(bytes);
|
||||
let addr = read_u64(&mut disk_image);
|
||||
@@ -33,6 +33,8 @@ fuzz_target!(|bytes| {
|
||||
let _ = qcow.write_all(&value.to_le_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
Corpus::Keep
|
||||
});
|
||||
|
||||
fn read_u64<T: Read>(readable: &mut T) -> u64 {
|
||||
|
||||
Reference in New Issue
Block a user