Skip to content

Commit

Permalink
Fix use after free in Rust bindings (keystone-engine#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmorenz authored and aquynh committed Apr 1, 2018
1 parent 3e67c1d commit 2829223
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bindings/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ impl Keystone {
});

if err == ERR_OK {
let bytes = unsafe { std::slice::from_raw_parts(ptr, size) };
let bytes_slice = unsafe { std::slice::from_raw_parts(ptr, size) };
let bytes = bytes_slice.to_vec();

unsafe {
ffi::ks_free(ptr);
Expand All @@ -173,7 +174,7 @@ impl Keystone {
Ok(AsmResult {
size: size as u32,
stat_count: stat_count as u32,
bytes: From::from(&bytes[..]),
bytes
})
} else {
let err = Error::from_bits_truncate(unsafe { ffi::ks_errno(self.handle) });
Expand Down

0 comments on commit 2829223

Please sign in to comment.