summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Ossevoort <github@internetionals.nl>2021-03-02 17:34:29 +0100
committerJustin Ossevoort <justin.ossevoort@tesorion.nl>2021-03-05 14:18:29 +0100
commit5fc15828af43ba81246e40b0453350a296124d65 (patch)
tree9354bc32207b329ac5591a6d575f7e13c25343b6
parenta45d3e45fab3d216ecf0bfb2189b0e15fb2d8167 (diff)
downloadnix-5fc15828af43ba81246e40b0453350a296124d65.zip
Allow sockaddr_ll size mismatch
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.
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/sys/socket/mod.rs5
2 files changed, 7 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54b89350..9636942d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 4db7ac6e..73f976b8 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -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)
};