Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
#![no_main]
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
use std::sync::Arc;
|
|
use usbip_rs::mock::MockSocket;
|
|
use usbip_rs::{
|
|
ClassCode, UsbDevice, UsbEndpoint, UsbInterfaceHandler, UsbIpServer,
|
|
hid::UsbHidKeyboardHandler,
|
|
};
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
|
.enable_all()
|
|
.build()
|
|
.unwrap();
|
|
rt.block_on(async {
|
|
let handler = Arc::new(UsbHidKeyboardHandler::new_keyboard());
|
|
let device = UsbDevice::new(0)
|
|
.unwrap()
|
|
.with_interface(
|
|
ClassCode::HID as u8,
|
|
0x00,
|
|
0x00,
|
|
Some("Fuzz HID Keyboard"),
|
|
vec![UsbEndpoint {
|
|
address: 0x81,
|
|
attributes: 0x03,
|
|
max_packet_size: 0x08,
|
|
interval: 10,
|
|
..Default::default()
|
|
}],
|
|
handler as Arc<dyn UsbInterfaceHandler>,
|
|
)
|
|
.unwrap();
|
|
|
|
let server = UsbIpServer::new_simulated(vec![device]);
|
|
let mock = MockSocket::new(data.to_vec());
|
|
let output = mock.output_handle();
|
|
let _ = usbip_rs::handler(mock, Arc::new(server)).await;
|
|
let output_bytes = output.lock().unwrap();
|
|
usbip_rs::fuzz_helpers::assert_usbip_responses_valid(&output_bytes);
|
|
});
|
|
});
|