From f7cdcd7e87efb6692456253c8148cdafa481cae9 Mon Sep 17 00:00:00 2001 From: Andrej Mihajlov Date: Tue, 17 Dec 2024 21:29:39 +0100 Subject: [PATCH 1/2] Parse unix address from sockaddr without length --- src/sys/socket/addr.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 003db4c3d3..a63065b3cd 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1189,6 +1189,9 @@ impl SockaddrLike for SockaddrStorage { libc::AF_ALG => unsafe { AlgAddr::from_raw(addr, l).map(|alg| Self { alg }) }, + libc::AF_UNIX => unsafe { + UnixAddr::from_raw(addr, l).map(|su| Self { su }) + }, #[cfg(feature = "net")] libc::AF_INET => unsafe { SockaddrIn::from_raw(addr, l).map(|sin| Self { sin }) From 618f557d41f8f9ec42c53532a2cd25b752f6d090 Mon Sep 17 00:00:00 2001 From: Andrej Mihajlov Date: Wed, 18 Dec 2024 11:52:31 +0100 Subject: [PATCH 2/2] Add test --- src/sys/socket/addr.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index a63065b3cd..ea87ae5ef1 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -2392,6 +2392,19 @@ mod tests { assert_eq!(ss.len(), ua.len()); } + #[test] + fn from_sockaddr_un_named_no_length() { + let ua = UnixAddr::new("/var/run/mysock").unwrap(); + assert!( + UnixAddr::size() + <= mem::size_of::() + as libc::socklen_t + ); + let ptr = ua.as_ptr().cast(); + let ss = unsafe { SockaddrStorage::from_raw(ptr, None) }.unwrap(); + assert_eq!(ss.len(), ua.len()); + } + #[cfg(linux_android)] #[test] fn from_sockaddr_un_abstract_named() {