Skip to content

Commit 4cfdd68

Browse files
committed
Fix UserRef<[T]>::copy_to_enclave_vec
It reinterprets uninitialized memory as initialized and does not drop existing elements of the Vec.
1 parent 7f28835 commit 4cfdd68

File tree

1 file changed

+3
-8
lines changed
  • library/std/src/sys/pal/sgx/abi/usercalls

1 file changed

+3
-8
lines changed

library/std/src/sys/pal/sgx/abi/usercalls/alloc.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -645,17 +645,12 @@ where
645645

646646
/// Copies the value from user memory and place it into `dest`. Afterwards,
647647
/// `dest` will contain exactly `self.len()` elements.
648-
///
649-
/// # Panics
650-
/// This function panics if the destination doesn't have the same size as
651-
/// the source. This can happen for dynamically-sized types such as slices.
652648
pub fn copy_to_enclave_vec(&self, dest: &mut Vec<T>) {
653-
if let Some(missing) = self.len().checked_sub(dest.capacity()) {
654-
dest.reserve(missing)
655-
}
649+
dest.clear();
650+
dest.reserve(self.len());
651+
self.copy_to_enclave_uninit(&mut dest.spare_capacity_mut()[..self.len()]);
656652
// SAFETY: We reserve enough space above.
657653
unsafe { dest.set_len(self.len()) };
658-
self.copy_to_enclave(&mut dest[..]);
659654
}
660655

661656
/// Copies the value from user memory and place it into `dest`.

0 commit comments

Comments
 (0)