summaryrefslogtreecommitdiff
path: root/src/sys/socket
diff options
context:
space:
mode:
authorKyle Huey <khuey@kylehuey.com>2021-08-09 22:45:54 -0700
committerKyle Huey <khuey@kylehuey.com>2021-08-17 19:26:12 -0700
commitd133d3db7699bdf61441764d4278533539208ee1 (patch)
tree10ba7a8d3258d38c1f982e150af30276e57ae340 /src/sys/socket
parent5ed5bb634fbef82c5dcd6e64e9b609dff08e378d (diff)
downloadnix-d133d3db7699bdf61441764d4278533539208ee1.zip
Relax assertions in sockaddr_storage_to_addr to match the documentation.
Fixes #1479
Diffstat (limited to 'src/sys/socket')
-rw-r--r--src/sys/socket/mod.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 733bd660..f701a731 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -1780,21 +1780,21 @@ pub fn sockaddr_storage_to_addr(
addr: &sockaddr_storage,
len: usize) -> Result<SockAddr> {
- assert!(len <= mem::size_of::<sockaddr_un>());
+ assert!(len <= mem::size_of::<sockaddr_storage>());
if len < mem::size_of_val(&addr.ss_family) {
return Err(Error::from(Errno::ENOTCONN));
}
match c_int::from(addr.ss_family) {
libc::AF_INET => {
- assert_eq!(len as usize, mem::size_of::<sockaddr_in>());
+ assert!(len as usize >= mem::size_of::<sockaddr_in>());
let sin = unsafe {
*(addr as *const sockaddr_storage as *const sockaddr_in)
};
Ok(SockAddr::Inet(InetAddr::V4(sin)))
}
libc::AF_INET6 => {
- assert_eq!(len as usize, mem::size_of::<sockaddr_in6>());
+ assert!(len as usize >= mem::size_of::<sockaddr_in6>());
let sin6 = unsafe {
*(addr as *const _ as *const sockaddr_in6)
};
@@ -1810,10 +1810,10 @@ pub fn sockaddr_storage_to_addr(
#[cfg(any(target_os = "android", target_os = "linux"))]
libc::AF_PACKET => {
use libc::sockaddr_ll;
+ // Don't assert anything about the size.
// 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)
};