about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorJethro Beekman <jethro@fortanix.com>2019-04-10 19:46:29 -0700
committerJethro Beekman <jethro@fortanix.com>2019-04-29 16:46:29 -0700
commit7e624ce2c2f5196a94178ce7dd62173526ff6839 (patch)
treecba07f80f52cf041cae2aae4c0ac23efb2e0eb80 /src/libstd/sys
parent00859e3e653973120006aaf3227823062dde1ba7 (diff)
downloadrust-7e624ce2c2f5196a94178ce7dd62173526ff6839.tar.gz
rust-7e624ce2c2f5196a94178ce7dd62173526ff6839.zip
SGX target: don't unwind on usercall index out of bounds
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/sgx/abi/usercalls/alloc.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libstd/sys/sgx/abi/usercalls/alloc.rs b/src/libstd/sys/sgx/abi/usercalls/alloc.rs
index 22ae2a8e07d..38e05f6fd27 100644
--- a/src/libstd/sys/sgx/abi/usercalls/alloc.rs
+++ b/src/libstd/sys/sgx/abi/usercalls/alloc.rs
@@ -523,7 +523,11 @@ impl<T, I: SliceIndex<[T]>> Index<I> for UserRef<[T]> where [T]: UserSafe, I::Ou
     #[inline]
     fn index(&self, index: I) -> &UserRef<I::Output> {
         unsafe {
-            UserRef::from_ptr(index.index(&*self.as_raw_ptr()))
+            if let Some(slice) = index.get(&*self.as_raw_ptr()) {
+                UserRef::from_ptr(slice)
+            } else {
+                rtabort!("index out of range for user slice");
+            }
         }
     }
 }
@@ -533,7 +537,11 @@ impl<T, I: SliceIndex<[T]>> IndexMut<I> for UserRef<[T]> where [T]: UserSafe, I:
     #[inline]
     fn index_mut(&mut self, index: I) -> &mut UserRef<I::Output> {
         unsafe {
-            UserRef::from_mut_ptr(index.index_mut(&mut*self.as_raw_mut_ptr()))
+            if let Some(slice) = index.get_mut(&mut*self.as_raw_mut_ptr()) {
+                UserRef::from_mut_ptr(slice)
+            } else {
+                rtabort!("index out of range for user slice");
+            }
         }
     }
 }