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

Consistent marking of functions as unsafe #982

Open
Niederb opened this issue Sep 8, 2022 · 1 comment
Open

Consistent marking of functions as unsafe #982

Niederb opened this issue Sep 8, 2022 · 1 comment
Labels

Comments

@Niederb
Copy link
Contributor

Niederb commented Sep 8, 2022

I feel we mark functions as unsafe in an inconsistent way at the moment. I think we should discuss this and establish some guidelines (are there some best practices from Rust).

A function such this one does nothing that is actually unsafe so I don't think it should be marked unsafe:

pub unsafe extern "C" fn trigger_parentchain_block_import() -> sgx_status_t {
	match GLOBAL_TRIGGERED_PARENTCHAIN_IMPORT_DISPATCHER_COMPONENT.get() {
		Ok(dispatcher) => match dispatcher.import_all() {
			Ok(_) => sgx_status_t::SGX_SUCCESS,
			Err(e) => {
				error!("Failed to trigger import of parentchain blocks: {:?}", e);
				sgx_status_t::SGX_ERROR_UNEXPECTED
			},
		},
		Err(e) => Error::ComponentContainer(e).into(),
	}
}

On the other hand I think this should be marked unsafe as the function cannot guarantee all these pointers are valid and the memory is of the correct size.

#[no_mangle]
pub extern "C" fn ocall_get_quote(
	p_sigrl: *const u8,
	sigrl_len: u32,
	p_report: *const sgx_report_t,
	quote_type: sgx_quote_sign_type_t,
	p_spid: *const sgx_spid_t,
	p_nonce: *const sgx_quote_nonce_t,
	p_qe_report: *mut sgx_report_t,
	p_quote: *mut u8,
	maxlen: u32,
	p_quote_len: *mut u32,
) -> sgx_status_t
@clangenb
Copy link
Contributor

I doubt that we can change this. The rust compiler complains if the upper one is not marked unsafe. We should be able to add an unsafe to the lower one though.

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

No branches or pull requests

2 participants