Skip to content

Commit

Permalink
Auto merge of #490 - kevindejong:master, r=fiveop
Browse files Browse the repository at this point in the history
Ensure child stack passed to clone is 16 byte aligned.

The current implementation assumes that the array passed by the caller is word aligned (which I don't think Rust guarantees for [u8]) and a multiple of the word size.
  • Loading branch information
homu committed Dec 16, 2016
2 parents 618737f + 7b98f0d commit 5e932dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#397](https://github.com/nix-rust/nix/pull/397))
- Fixed an off-by-one bug in `UnixAddr::new_abstract` in `::nix::sys::socket`.
([#429](https://github.com/nix-rust/nix/pull/429))
- Fixed clone passing a potentially unaligned stack.
([#490](https://github.com/nix-rust/nix/pull/490))

## [0.7.0] 2016-09-09

Expand Down
3 changes: 2 additions & 1 deletion src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ pub fn clone(mut cb: CloneCb,
let res = unsafe {
let combined = flags.bits() | signal.unwrap_or(0);
let ptr = stack.as_mut_ptr().offset(stack.len() as isize);
let ptr_aligned = ptr.offset((ptr as usize % 16) as isize * -1);
ffi::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32),
ptr as *mut c_void,
ptr_aligned as *mut c_void,
combined,
&mut cb)
};
Expand Down

0 comments on commit 5e932dc

Please sign in to comment.