Skip to content

Commit 7e624ce

Browse files
author
Jethro Beekman
committed
SGX target: don't unwind on usercall index out of bounds
1 parent 00859e3 commit 7e624ce

File tree

1 file changed

+10
-2
lines changed
  • src/libstd/sys/sgx/abi/usercalls

1 file changed

+10
-2
lines changed

src/libstd/sys/sgx/abi/usercalls/alloc.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,11 @@ impl<T, I: SliceIndex<[T]>> Index<I> for UserRef<[T]> where [T]: UserSafe, I::Ou
523523
#[inline]
524524
fn index(&self, index: I) -> &UserRef<I::Output> {
525525
unsafe {
526-
UserRef::from_ptr(index.index(&*self.as_raw_ptr()))
526+
if let Some(slice) = index.get(&*self.as_raw_ptr()) {
527+
UserRef::from_ptr(slice)
528+
} else {
529+
rtabort!("index out of range for user slice");
530+
}
527531
}
528532
}
529533
}
@@ -533,7 +537,11 @@ impl<T, I: SliceIndex<[T]>> IndexMut<I> for UserRef<[T]> where [T]: UserSafe, I:
533537
#[inline]
534538
fn index_mut(&mut self, index: I) -> &mut UserRef<I::Output> {
535539
unsafe {
536-
UserRef::from_mut_ptr(index.index_mut(&mut*self.as_raw_mut_ptr()))
540+
if let Some(slice) = index.get_mut(&mut*self.as_raw_mut_ptr()) {
541+
UserRef::from_mut_ptr(slice)
542+
} else {
543+
rtabort!("index out of range for user slice");
544+
}
537545
}
538546
}
539547
}

0 commit comments

Comments
 (0)