Skip to content

Commit

Permalink
Merge #1395
Browse files Browse the repository at this point in the history
1395: Allow sockaddr_ll size mismatch r=asomers a=internetionals

Apparently the Linux kernel can return smaller sizes when the value in
the last element of sockaddr_ll (`sll_addr`) is smaller than the
declared size of that field.

Co-authored-by: Justin Ossevoort <[email protected]>
  • Loading branch information
bors[bot] and internetionals authored Mar 6, 2021
2 parents a45d3e4 + 5fc1582 commit 2d36e3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
(#[1390](https://github.com/nix-rust/nix/pull/1390))

### Fixed
- Allow `sockaddr_ll` size, as reported by the Linux kernel, to be smaller then it's definition
(#[1395](https://github.com/nix-rust/nix/pull/1395))

### Removed

- Removed `sys::socket::accept4` from Android arm because libc removed it in
Expand Down
5 changes: 4 additions & 1 deletion src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,10 @@ pub fn sockaddr_storage_to_addr(
#[cfg(any(target_os = "android", target_os = "linux"))]
libc::AF_PACKET => {
use libc::sockaddr_ll;
assert_eq!(len as usize, mem::size_of::<sockaddr_ll>());
// Apparently the Linux kernel can return smaller sizes when
// the value in the last element of sockaddr_ll (`sll_addr`) is
// smaller than the declared size of that field
assert!(len as usize <= mem::size_of::<sockaddr_ll>());
let sll = unsafe {
*(addr as *const _ as *const sockaddr_ll)
};
Expand Down

0 comments on commit 2d36e3a

Please sign in to comment.