-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fuzz_storvsp: remove last round of TODO: [use-arbitrary-input] #669
base: main
Are you sure you want to change the base?
Conversation
34a0602
to
47fff83
Compare
and remove some `TODO: [use-arbitrary-input]`.
99b2d79
to
9687725
Compare
@@ -120,7 +239,11 @@ async fn send_arbitrary_readwrite_packet( | |||
length: protocol::SCSI_REQUEST_LEN_V2 as u16, | |||
cdb_length: size_of::<Cdb10>() as u8, | |||
data_transfer_length: byte_len.try_into()?, | |||
data_in: 1, | |||
data_in: if cdb.operation_code == ScsiOp::READ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data_in: (cdb.operation_code == ScsiOp::READ) as u8
could be a more concise way of doing this. (Credits: Copilot)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
|
||
match op { | ||
TargetScsiOp::Inquiry => { | ||
let mut bytes = vec![0; size_of::<CdbInquiry>()]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sounding quite repetitive. If possible, consider writing a generic function for this?
fn get_buffer<T: FromBytes>(u: &mut Unstructured<'_>) -> Result<T, arbitrary::Error> {
let mut bytes = vec![0; size_of::<T>()];
u.fill_buffer(&mut bytes)?;
let val = T::mut_from_bytes(bytes.as_mut_slice())
.map_err(|_| arbitrary::Error::IncorrectFormat)?;
Ok(val)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I actually worked up a better way to do this (incoming), but this is helpful :)
cdb.operation_code = ScsiOp::READ; | ||
cdb.transfer_blocks = ((arbitrary_byte_len(u)? / 512) as u32).into(); | ||
|
||
scsi_req.payload[0..(bytes.len())].copy_from_slice(bytes.as_slice()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe have the match function return the bytes as well to move this outside the match function. Something like:
let bytes = match op {
TargetScsiOp::Inquiry => {
.....
bytes
}
};
scsi_req.payload[0..(bytes.len())].copy_from_slice(bytes.as_slice());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried this already. The bytes
does not live long enough to be returned from the match (I guess I could figure out a way to copy them out, but I couldn't seem to get that to work)
host, | ||
None, | ||
); | ||
let _worker = TestWorker::start(&controller, driver.clone(), test_guest_mem, host, None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the correct type? TestWorker::start takes in : &ScsiController
. &controller
is of type &Arc<ScsiController>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, it complies? Let me check.
Changes in storvsp fuzzer to increase code coverage in key areas and remove some
TODO: [use-arbitrary-input]
.