2022-09-13 17:55:17 +00:00
|
|
|
// Copyright 2019 The ChromiumOS Authors
|
2019-03-13 21:24:18 +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:24:18 +00:00
|
|
|
#![no_main]
|
|
|
|
|
2022-07-27 18:11:32 +00:00
|
|
|
use std::io::Cursor;
|
|
|
|
use std::io::Read;
|
|
|
|
use std::io::Seek;
|
|
|
|
use std::io::SeekFrom;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::mem::size_of;
|
|
|
|
|
2022-02-14 23:28:17 +00:00
|
|
|
use base::FileReadWriteAtVolatile;
|
2019-10-24 17:25:16 +00:00
|
|
|
use cros_fuzz::fuzz_target;
|
2022-02-14 23:28:17 +00:00
|
|
|
use data_model::VolatileSlice;
|
2019-12-18 01:04:58 +00:00
|
|
|
use disk::QcowFile;
|
2019-03-13 21:24:18 +00:00
|
|
|
|
|
|
|
// 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.
|
2019-10-24 17:25:16 +00:00
|
|
|
fuzz_target!(|bytes| {
|
|
|
|
if bytes.len() < 16 {
|
|
|
|
// Need an address and data, each are 8 bytes.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut disk_image = Cursor::new(bytes);
|
|
|
|
let addr = read_u64(&mut disk_image);
|
|
|
|
let value = read_u64(&mut disk_image);
|
2021-09-07 21:09:31 +00:00
|
|
|
let max_nesting_depth = 10;
|
2020-10-09 21:08:27 +00:00
|
|
|
let mut disk_file = tempfile::tempfile().unwrap();
|
2019-10-24 17:25:16 +00:00
|
|
|
disk_file.write_all(&bytes[16..]).unwrap();
|
|
|
|
disk_file.seek(SeekFrom::Start(0)).unwrap();
|
2021-09-07 21:09:31 +00:00
|
|
|
if let Ok(mut qcow) = QcowFile::from(disk_file, max_nesting_depth) {
|
2022-02-14 23:28:17 +00:00
|
|
|
let mut mem = value.to_le_bytes().to_owned();
|
|
|
|
let vslice = VolatileSlice::new(&mut mem);
|
|
|
|
let _ = qcow.write_all_at_volatile(vslice, addr);
|
2019-10-24 17:25:16 +00:00
|
|
|
}
|
|
|
|
});
|
2019-03-13 21:24:18 +00:00
|
|
|
|
|
|
|
fn read_u64<T: Read>(readable: &mut T) -> u64 {
|
|
|
|
let mut buf = [0u8; size_of::<u64>()];
|
|
|
|
readable.read_exact(&mut buf[..]).unwrap();
|
|
|
|
u64::from_le_bytes(buf)
|
|
|
|
}
|