Skip to content

Commit 0a99945

Browse files
author
Gleb Pomykalov
committed
Fix unaligned castting of cmsg data to af_alg_iv
1 parent b5ee610 commit 0a99945

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2828
- Fixed a bug in nix::unistd that would result in an infinite loop
2929
when a group or user lookup required a buffer larger than
3030
16KB. (#[1198](https://github.com/nix-rust/nix/pull/1198))
31+
- Fixed unaligned casting of `cmsg_data` to `af_alg_iv` (#[1206](https://github.com/nix-rust/nix/pull/1206))
3132

3233
### Removed
3334

src/sys/socket/mod.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -657,15 +657,26 @@ impl<'a> ControlMessage<'a> {
657657
}
658658
#[cfg(any(target_os = "android", target_os = "linux"))]
659659
ControlMessage::AlgSetIv(iv) => {
660+
let af_alg_iv = libc::af_alg_iv {
661+
ivlen: iv.len() as u32,
662+
iv: [0u8; 0],
663+
};
664+
665+
let size = mem::size_of::<libc::af_alg_iv>();
666+
660667
unsafe {
661-
let alg_iv = cmsg_data as *mut libc::af_alg_iv;
662-
(*alg_iv).ivlen = iv.len() as u32;
668+
ptr::copy_nonoverlapping(
669+
&af_alg_iv as *const _ as *const u8,
670+
cmsg_data,
671+
size,
672+
);
663673
ptr::copy_nonoverlapping(
664674
iv.as_ptr(),
665-
(*alg_iv).iv.as_mut_ptr(),
675+
cmsg_data.add(size),
666676
iv.len()
667677
);
668678
};
679+
669680
return
670681
},
671682
#[cfg(any(target_os = "android", target_os = "linux"))]

0 commit comments

Comments
 (0)