From 5fc15828af43ba81246e40b0453350a296124d65 Mon Sep 17 00:00:00 2001 From: Justin Ossevoort Date: Tue, 2 Mar 2021 17:34:29 +0100 Subject: [PATCH] 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. --- CHANGELOG.md | 3 +++ src/sys/socket/mod.rs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54b8935009..9636942d5f 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 4db7ac6ef3..73f976b808 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::()); + // 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::()); let sll = unsafe { *(addr as *const _ as *const sockaddr_ll) };