@@ -85,8 +85,10 @@ pub unsafe trait UserSafe {
85
85
///
86
86
/// * the pointer is not aligned.
87
87
/// * the pointer is null.
88
+ /// * the pointed-to range does not fit in the address space.
88
89
/// * the pointed-to range is not in user memory.
89
90
unsafe fn from_raw_sized ( ptr : * mut u8 , size : usize ) -> NonNull < Self > {
91
+ assert ! ( ptr. wrapping_add( size) >= ptr) ;
90
92
let ret = Self :: from_raw_sized_unchecked ( ptr, size) ;
91
93
Self :: check_ptr ( ret) ;
92
94
NonNull :: new_unchecked ( ret as _ )
@@ -268,6 +270,7 @@ impl<T> User<[T]> where [T]: UserSafe {
268
270
///
269
271
/// * The pointer is not aligned
270
272
/// * The pointer is null
273
+ /// * The pointed-to range does not fit in the address space
271
274
/// * The pointed-to range is not in user memory
272
275
pub unsafe fn from_raw_parts ( ptr : * mut T , len : usize ) -> Self {
273
276
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 {
372
375
///
373
376
/// * The pointer is not aligned
374
377
/// * The pointer is null
378
+ /// * The pointed-to range does not fit in the address space
375
379
/// * The pointed-to range is not in user memory
376
380
pub unsafe fn from_raw_parts < ' a > ( ptr : * const T , len : usize ) -> & ' a Self {
377
381
& * ( <[ 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 {
389
393
///
390
394
/// * The pointer is not aligned
391
395
/// * The pointer is null
396
+ /// * The pointed-to range does not fit in the address space
392
397
/// * The pointed-to range is not in user memory
393
398
pub unsafe fn from_raw_parts_mut < ' a > ( ptr : * mut T , len : usize ) -> & ' a mut Self {
394
399
& 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> {
552
557
/// enclave memory.
553
558
///
554
559
/// # Panics
555
- /// This function panics if:
560
+ /// This function panics if, in the user `ByteBuffer` :
556
561
///
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
559
565
pub fn copy_user_buffer ( & self ) -> Vec < u8 > {
560
566
unsafe {
561
567
let buf = self . to_enclave ( ) ;
0 commit comments