@@ -85,8 +85,10 @@ pub unsafe trait UserSafe {
8585 ///
8686 /// * the pointer is not aligned.
8787 /// * the pointer is null.
88+ /// * the pointed-to range does not fit in the address space.
8889 /// * the pointed-to range is not in user memory.
8990 unsafe fn from_raw_sized ( ptr : * mut u8 , size : usize ) -> NonNull < Self > {
91+ assert ! ( ptr. wrapping_add( size) >= ptr) ;
9092 let ret = Self :: from_raw_sized_unchecked ( ptr, size) ;
9193 Self :: check_ptr ( ret) ;
9294 NonNull :: new_unchecked ( ret as _ )
@@ -268,6 +270,7 @@ impl<T> User<[T]> where [T]: UserSafe {
268270 ///
269271 /// * The pointer is not aligned
270272 /// * The pointer is null
273+ /// * The pointed-to range does not fit in the address space
271274 /// * The pointed-to range is not in user memory
272275 pub unsafe fn from_raw_parts ( ptr : * mut T , len : usize ) -> Self {
273276 User ( NonNull :: new_userref ( <[ T ] >:: from_raw_sized ( ptr as _ , len * mem:: size_of :: < T > ( ) ) ) )
@@ -372,6 +375,7 @@ impl<T> UserRef<[T]> where [T]: UserSafe {
372375 ///
373376 /// * The pointer is not aligned
374377 /// * The pointer is null
378+ /// * The pointed-to range does not fit in the address space
375379 /// * The pointed-to range is not in user memory
376380 pub unsafe fn from_raw_parts < ' a > ( ptr : * const T , len : usize ) -> & ' a Self {
377381 & * ( <[ T ] >:: from_raw_sized ( ptr as _ , len * mem:: size_of :: < T > ( ) ) . as_ptr ( ) as * const Self )
@@ -389,6 +393,7 @@ impl<T> UserRef<[T]> where [T]: UserSafe {
389393 ///
390394 /// * The pointer is not aligned
391395 /// * The pointer is null
396+ /// * The pointed-to range does not fit in the address space
392397 /// * The pointed-to range is not in user memory
393398 pub unsafe fn from_raw_parts_mut < ' a > ( ptr : * mut T , len : usize ) -> & ' a mut Self {
394399 & mut * ( <[ T ] >:: from_raw_sized ( ptr as _ , len * mem:: size_of :: < T > ( ) ) . as_ptr ( ) as * mut Self )
@@ -552,10 +557,11 @@ impl UserRef<super::raw::ByteBuffer> {
552557 /// enclave memory.
553558 ///
554559 /// # Panics
555- /// This function panics if:
560+ /// This function panics if, in the user `ByteBuffer` :
556561 ///
557- /// * The pointer in the user `ByteBuffer` is null
558- /// * The pointed-to range in the user `ByteBuffer` is not in user memory
562+ /// * The pointer is null
563+ /// * The pointed-to range does not fit in the address space
564+ /// * The pointed-to range is not in user memory
559565 pub fn copy_user_buffer ( & self ) -> Vec < u8 > {
560566 unsafe {
561567 let buf = self . to_enclave ( ) ;
0 commit comments