fix: add pointer null check on ecall function
diff --git a/samplecode/http_req/enclave/src/lib.rs b/samplecode/http_req/enclave/src/lib.rs
index c490d69..1524448 100644
--- a/samplecode/http_req/enclave/src/lib.rs
+++ b/samplecode/http_req/enclave/src/lib.rs
@@ -36,6 +36,10 @@
#[no_mangle]
pub extern "C" fn send_http_request(hostname: *const c_char) -> sgx_status_t {
+ if hostname.is_null() {
+ return sgx_status_t::SGX_ERROR_UNEXPECTED;
+ }
+
let hostname = unsafe { CStr::from_ptr(hostname).to_str() };
let hostname = hostname.expect("Failed to recover hostname");
diff --git a/samplecode/tls/tlsclient/enclave/src/lib.rs b/samplecode/tls/tlsclient/enclave/src/lib.rs
index c4ce216..5295295 100644
--- a/samplecode/tls/tlsclient/enclave/src/lib.rs
+++ b/samplecode/tls/tlsclient/enclave/src/lib.rs
@@ -287,6 +287,10 @@
#[no_mangle]
pub extern "C" fn tls_client_new(fd: c_int, hostname: * const c_char, cert: * const c_char) -> usize {
+ if hostname.is_null() {
+ return 0xFFFF_FFFF_FFFF_FFFF;
+ }
+
let certfile = unsafe { CStr::from_ptr(cert).to_str() };
if certfile.is_err() {
return 0xFFFF_FFFF_FFFF_FFFF;
diff --git a/sgx_tstd/src/rt.rs b/sgx_tstd/src/rt.rs
index e90fa24..ab97c0e 100644
--- a/sgx_tstd/src/rt.rs
+++ b/sgx_tstd/src/rt.rs
@@ -56,6 +56,10 @@
#[no_mangle]
pub extern "C" fn t_global_init_ecall(id: u64, path: *const u8, len: usize) {
+ if path.is_null() {
+ return;
+ }
+
GLOBAL_INIT_LOCK.lock();
unsafe { INIT_TCS = thread::rsgx_thread_self() };