File tree 2 files changed +8
-2
lines changed
src/libstd/sys/sgx/abi/usercalls
2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -537,7 +537,12 @@ impl UserRef<super::raw::ByteBuffer> {
537
537
pub fn copy_user_buffer ( & self ) -> Vec < u8 > {
538
538
unsafe {
539
539
let buf = self . to_enclave ( ) ;
540
- User :: from_raw_parts ( buf. data as _ , buf. len ) . to_enclave ( )
540
+ if buf. len > 0 {
541
+ User :: from_raw_parts ( buf. data as _ , buf. len ) . to_enclave ( )
542
+ } else {
543
+ // Mustn't look at `data` or call `free` if `len` is `0`.
544
+ Vec :: with_capacity ( 0 )
545
+ }
541
546
}
542
547
}
543
548
}
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ pub fn read(fd: Fd, buf: &mut [u8]) -> IoResult<usize> {
22
22
#[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
23
23
pub fn read_alloc ( fd : Fd ) -> IoResult < Vec < u8 > > {
24
24
unsafe {
25
- let mut userbuf = alloc:: User :: < ByteBuffer > :: uninitialized ( ) ;
25
+ let userbuf = ByteBuffer { data : :: ptr:: null_mut ( ) , len : 0 } ;
26
+ let mut userbuf = alloc:: User :: new_from_enclave ( & userbuf) ;
26
27
raw:: read_alloc ( fd, userbuf. as_raw_mut_ptr ( ) ) . from_sgx_result ( ) ?;
27
28
Ok ( userbuf. copy_user_buffer ( ) )
28
29
}
You can’t perform that action at this time.
0 commit comments