Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mattkur
Copy link
Contributor

@mattkur mattkur commented Jan 15, 2025

Changes in storvsp fuzzer to increase code coverage in key areas and remove some TODO: [use-arbitrary-input].

and remove some `TODO: [use-arbitrary-input]`.
@@ -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 {
Copy link
Contributor

@gurasinghMS gurasinghMS Feb 12, 2025

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)

Copy link
Contributor Author

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>()];
Copy link
Contributor

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)
}

Copy link
Contributor Author

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());
Copy link
Contributor

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());

Copy link
Contributor Author

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);
Copy link
Contributor

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>.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants