feat: add fuzz_handle_client target
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
60bef00b00
commit
0e6b602b1d
1 changed files with 43 additions and 0 deletions
43
lib/fuzz/fuzz_targets/fuzz_handle_client.rs
Normal file
43
lib/fuzz/fuzz_targets/fuzz_handle_client.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#![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);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue