File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
src/libstd/sys/sgx/abi/usercalls Expand file tree Collapse file tree 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> {
537537 pub fn copy_user_buffer ( & self ) -> Vec < u8 > {
538538 unsafe {
539539 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+ }
541546 }
542547 }
543548}
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ pub fn read(fd: Fd, buf: &mut [u8]) -> IoResult<usize> {
2222#[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
2323pub fn read_alloc ( fd : Fd ) -> IoResult < Vec < u8 > > {
2424 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) ;
2627 raw:: read_alloc ( fd, userbuf. as_raw_mut_ptr ( ) ) . from_sgx_result ( ) ?;
2728 Ok ( userbuf. copy_user_buffer ( ) )
2829 }
You can’t perform that action at this time.
0 commit comments