summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/sys/socket/mod.rs17
2 files changed, 15 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1498c0ca..09628180 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fixed a bug in nix::unistd that would result in an infinite loop
when a group or user lookup required a buffer larger than
16KB. (#[1198](https://github.com/nix-rust/nix/pull/1198))
+- Fixed unaligned casting of `cmsg_data` to `af_alg_iv` (#[1206](https://github.com/nix-rust/nix/pull/1206))
### Removed
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index aa280747..6b2d1ad0 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -657,15 +657,26 @@ impl<'a> ControlMessage<'a> {
}
#[cfg(any(target_os = "android", target_os = "linux"))]
ControlMessage::AlgSetIv(iv) => {
+ let af_alg_iv = libc::af_alg_iv {
+ ivlen: iv.len() as u32,
+ iv: [0u8; 0],
+ };
+
+ let size = mem::size_of::<libc::af_alg_iv>();
+
unsafe {
- let alg_iv = cmsg_data as *mut libc::af_alg_iv;
- (*alg_iv).ivlen = iv.len() as u32;
+ ptr::copy_nonoverlapping(
+ &af_alg_iv as *const _ as *const u8,
+ cmsg_data,
+ size,
+ );
ptr::copy_nonoverlapping(
iv.as_ptr(),
- (*alg_iv).iv.as_mut_ptr(),
+ cmsg_data.add(size),
iv.len()
);
};
+
return
},
#[cfg(any(target_os = "android", target_os = "linux"))]