File tree 3 files changed +9
-3
lines changed
3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ pub mod usercalls {
16
16
/// Primitives for allocating memory in userspace as well as copying data
17
17
/// to and from user memory.
18
18
pub mod alloc {
19
- pub use sys:: abi:: usercalls:: alloc;
19
+ pub use sys:: abi:: usercalls:: alloc:: * ;
20
20
}
21
21
22
22
/// Lowest-level interfaces to usercalls and usercall ABI type definitions.
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