]> git.lizzy.rs Git - rust.git/commitdiff
SGX target: don't unwind on usercall index out of bounds
authorJethro Beekman <jethro@fortanix.com>
Thu, 11 Apr 2019 02:46:29 +0000 (19:46 -0700)
committerJethro Beekman <jethro@fortanix.com>
Mon, 29 Apr 2019 23:46:29 +0000 (16:46 -0700)
src/libstd/sys/sgx/abi/usercalls/alloc.rs

index 22ae2a8e07d313a3745c903a0513e94404684219..38e05f6fd2757a4816eb083ed8277835176bdfa9 100644 (file)
@@ -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");
+            }
         }
     }
 }