Fix multiplication overflow
This commit is contained in:
parent
96bfe7eeae
commit
1101bdf9e7
@ -26,7 +26,10 @@ pub mod from_user {
|
|||||||
|
|
||||||
/// Check the readonly array is within the readable memory of the user process
|
/// Check the readonly array is within the readable memory of the user process
|
||||||
pub fn check_array<T>(user_buf: *const T, count: usize) -> Result<()> {
|
pub fn check_array<T>(user_buf: *const T, count: usize) -> Result<()> {
|
||||||
if !is_inside_user_space(user_buf as *const u8, count * size_of::<T>()) {
|
let checked_len = count
|
||||||
|
.checked_mul(size_of::<T>())
|
||||||
|
.ok_or_else(|| errno!(EINVAL, "the array is too long"))?;
|
||||||
|
if !is_inside_user_space(user_buf as *const u8, checked_len) {
|
||||||
return_errno!(EFAULT, "the whole buffer is not in the user space");
|
return_errno!(EFAULT, "the whole buffer is not in the user space");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -109,10 +112,10 @@ pub mod from_untrusted {
|
|||||||
|
|
||||||
/// Check the untrusted array is outside the enclave
|
/// Check the untrusted array is outside the enclave
|
||||||
pub fn check_array<T>(out_ptr: *const T, count: usize) -> Result<()> {
|
pub fn check_array<T>(out_ptr: *const T, count: usize) -> Result<()> {
|
||||||
if !sgx_trts::trts::rsgx_raw_is_outside_enclave(
|
let checked_len = count
|
||||||
out_ptr as *const u8,
|
.checked_mul(size_of::<T>())
|
||||||
count * size_of::<T>(),
|
.ok_or_else(|| errno!(EINVAL, "the array is too long"))?;
|
||||||
) {
|
if !sgx_trts::trts::rsgx_raw_is_outside_enclave(out_ptr as *const u8, checked_len) {
|
||||||
return_errno!(EFAULT, "the whole buffer is not outside enclave");
|
return_errno!(EFAULT, "the whole buffer is not outside enclave");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user