Skip to content

Commit

Permalink
Fix libfuzzer build issue.
Browse files Browse the repository at this point in the history
1. Fix libfuzzer cases build issues.
2. add libfuzzer cases to build.sh.

Signed-off-by: xiaoyuxlu <[email protected]>
  • Loading branch information
xiaoyuxlu authored and jyao1 committed Mar 1, 2024
1 parent 7c61e7e commit 1b91bd6
Show file tree
Hide file tree
Showing 40 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion fuzz-target/fuzzlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use spdmlib;
pub use spdmlib::common::{SpdmDeviceIo, SpdmTransportEncap};
pub use spdmlib::error::SpdmResult;
pub use spdmlib::{common, config, error, protocol, requester, responder};
pub use spin;
pub use spin::{self, Mutex};

pub use flexi_logger;
pub use flexi_logger::FileSpec;
Expand Down
3 changes: 1 addition & 2 deletions fuzz-target/requester/version_req/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use fuzzlib::{
spdmlib::protocol::MAX_SPDM_VERSION_COUNT,
spdmlib::{protocol::SpdmVersion, requester::RequesterContext},
time::SPDM_TIME_IMPL,
PciDoeTransportEncap, SharedBuffer, SECRET_ASYM_IMPL_INSTANCE,
Mutex, PciDoeTransportEncap, SharedBuffer, SECRET_ASYM_IMPL_INSTANCE,
};

#[allow(unused)]
use fuzzlib::flexi_logger;

use spin::Mutex;
extern crate alloc;
use alloc::boxed::Box;
use alloc::sync::Arc;
Expand Down
3 changes: 3 additions & 0 deletions sh_script/fuzz_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ if [[ $fuzz_target_name ]]; then
else
set -x
cargo afl build --features "fuzz ${MUT_AUTH_FEATURE}" ${FUZZ_NO_DEFAULT_FEATURES} $buildpackage
pushd spdmlib
cargo fuzz build --release
popd
set -x
fi

Expand Down
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/algorithm_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/algorithm_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_algorithm(data);
let _ = fuzz_send_receive_spdm_algorithm(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/algorithm_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/algorithm_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_algorithm(data);
let _ = fuzz_handle_spdm_algorithm(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/capability_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/capability_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_capability(data);
let _ = fuzz_send_receive_spdm_capability(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/capability_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/capability_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_capability(data);
let _ = fuzz_handle_spdm_capability(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/certificate_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/certificate_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_certificate(data);
let _ = fuzz_send_receive_spdm_certificate(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/certificate_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/certificate_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_certificate(data);
let _ = fuzz_handle_spdm_certificate(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/challenge_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/challenge_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_challenge(data);
let _ = fuzz_send_receive_spdm_challenge(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/challenge_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/challenge_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_challenge(data);
let _ = fuzz_handle_spdm_challenge(Arc::new(data.to_vec()));
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/deliver_encapsulated_response_certifica

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_encap_response_certificate(data);
let _ = fuzz_handle_encap_response_certificate(Arc::new(data.to_vec()));
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/deliver_encapsulated_response_digest_rs

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_encap_response_digest(data);
let _ = fuzz_handle_encap_response_digest(Arc::new(data.to_vec()));
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/deliver_encapsulated_response_rsp/src/m

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_deliver_encapsulated_reponse(data);
let _ = fuzz_handle_deliver_encapsulated_reponse(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/digest_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/digest_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_digest(data);
let _ = fuzz_send_receive_spdm_digest(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/digest_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/digest_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_digest(data);
let _ = fuzz_handle_spdm_digest(Arc::new(data.to_vec()));
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/encapsulated_request_certificate_req/sr

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_encap_handle_get_certificate(data);
let _ = fuzz_encap_handle_get_certificate(Arc::new(data.to_vec()));
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/encapsulated_request_digest_req/src/mai

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_encap_handle_get_digest(data);
let _ = fuzz_encap_handle_get_digest(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/encapsulated_request_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/encapsulated_request_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_session_based_mutual_authenticate(data);
let _ = fuzz_session_based_mutual_authenticate(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/end_session_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/end_session_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_end_session(data);
let _ = fuzz_send_receive_spdm_end_session(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/end_session_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/end_session_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_end_session(data);
let _ = fuzz_handle_spdm_end_session(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/finish_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/finish_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_finish(data);
let _ = fuzz_send_receive_spdm_finish(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/finish_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/finish_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_finish(data);
let _ = fuzz_handle_spdm_finish(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/get_encapsulated_request_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/get_encapsulated_request_rsp/src/main.r

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_get_encapsulated_request(data);
let _ = fuzz_handle_get_encapsulated_request(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/heartbeat_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/heartbeat_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_heartbeat(data);
let _ = fuzz_send_receive_spdm_heartbeat(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/heartbeat_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/heartbeat_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_heartbeat(data);
let _ = fuzz_handle_spdm_heartbeat(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/key_exchange_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/key_exchange_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_key_exchange(data);
let _ = fuzz_send_receive_spdm_key_exchange(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/key_update_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/key_update_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_key_update(data);
let _ = fuzz_send_receive_spdm_key_update(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/key_update_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/key_update_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_key_update(data);
let _ = fuzz_handle_spdm_key_update(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/keyexchange_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/keyexchange_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_key_exchange(data);
let _ = fuzz_handle_spdm_key_exchange(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/measurement_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/measurement_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_measurement(data);
let _ = fuzz_send_receive_spdm_measurement(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/measurement_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/measurement_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_measurement(data);
let _ = fuzz_handle_spdm_measurement(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/psk_exchange_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/psk_exchange_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_psk_exchange(data);
let _ = fuzz_send_receive_spdm_psk_exchange(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/psk_finish_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/psk_finish_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_psk_finish(data);
let _ = fuzz_send_receive_spdm_psk_finish(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/psk_finish_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/psk_finish_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_psk_finish(data);
let _ = fuzz_handle_spdm_psk_finish(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/pskexchange_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/pskexchange_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_psk_exchange(data);
let _ = fuzz_handle_spdm_psk_exchange(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/vendor_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/vendor_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_spdm_vendor_defined_request(data);
let _ = fuzz_send_spdm_vendor_defined_request(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/vendor_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/vendor_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_vendor_defined_request(data);
let _ = fuzz_handle_spdm_vendor_defined_request(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/version_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/requester/version_req/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_send_receive_spdm_version(data);
let _ = fuzz_send_receive_spdm_version(Arc::new(data.to_vec()));
});
2 changes: 1 addition & 1 deletion spdmlib/fuzz/fuzz_targets/version_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ include!("../../../fuzz-target/responder/version_rsp/src/main.rs");

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
fuzz_handle_spdm_version(data);
let _ = fuzz_handle_spdm_version(Arc::new(data.to_vec()));
});

0 comments on commit 1b91bd6

Please sign in to comment.