Fix dangling buffer pointer bug in dcap demo

Signed-off-by: Zheng, Qi <huaiqing.zq@antgroup.com>
This commit is contained in:
Zheng, Qi 2021-09-17 14:54:05 +08:00 committed by Zongmin.Gu
parent 663fc7273a
commit 339f25a84b

@ -8,10 +8,10 @@ use sgx_types::{
struct DcapDemo {
dcap_quote: DcapQuote,
quote_size: u32,
quote_buf_ptr: *mut u8,
quote_buf: Vec<u8>,
req_data: sgx_report_data_t,
supplemental_size: u32,
suppl_buf_ptr: *mut u8,
suppl_buf: Vec<u8>
}
impl DcapDemo {
@ -19,10 +19,8 @@ impl DcapDemo {
let mut dcap = DcapQuote::new();
let quote_size = dcap.get_quote_size();
let supplemental_size = dcap.get_supplemental_data_size();
let mut quote_buf: Vec<u8> = vec![0; quote_size as usize];
let quote_ptr = quote_buf.as_mut_ptr();
let mut suppl_buf: Vec<u8> = vec![0; supplemental_size as usize];
let suppl_ptr = suppl_buf.as_mut_ptr();
let quote_buf: Vec<u8> = vec![0; quote_size as usize];
let suppl_buf: Vec<u8> = vec![0; supplemental_size as usize];
let mut req_data = sgx_report_data_t::default();
//fill in the report data array
@ -33,15 +31,15 @@ impl DcapDemo {
Self {
dcap_quote: dcap,
quote_size: quote_size,
quote_buf_ptr: quote_ptr,
quote_buf: quote_buf,
req_data: req_data,
supplemental_size: supplemental_size,
suppl_buf_ptr: suppl_ptr
suppl_buf: suppl_buf
}
}
fn dcap_quote_gen(&mut self) -> Result<i32, &'static str> {
self.dcap_quote.generate_quote(self.quote_buf_ptr, &mut self.req_data).unwrap();
self.dcap_quote.generate_quote(self.quote_buf.as_mut_ptr(), &mut self.req_data).unwrap();
println!("DCAP generate quote successfully");
@ -49,7 +47,7 @@ impl DcapDemo {
}
fn dcap_quote_get_report_body(&mut self) -> Result<*const sgx_report_body_t, &'static str> {
let quote3: *mut sgx_quote3_t = self.quote_buf_ptr as *mut sgx_quote3_t;
let quote3: *mut sgx_quote3_t = self.quote_buf.as_mut_ptr() as *mut sgx_quote3_t;
let report_body = unsafe { &((*quote3).report_body) };
Ok(report_body)
@ -67,12 +65,12 @@ impl DcapDemo {
let mut status = 1;
let mut verify_arg = IoctlVerDCAPQuoteArg {
quote_buf: self.quote_buf_ptr,
quote_buf: self.quote_buf.as_mut_ptr(),
quote_size: self.quote_size,
collateral_expiration_status: &mut status,
quote_verification_result: &mut quote_verification_result,
supplemental_data_size: self.supplemental_size,
supplemental_data: self.suppl_buf_ptr,
supplemental_data: self.suppl_buf.as_mut_ptr(),
};
self.dcap_quote.verify_quote(&mut verify_arg).unwrap();