Skip to content

Commit

Permalink
Fix UnixSocketAddr::new_unspecified() being kinda short on BSDs
Browse files Browse the repository at this point in the history
Some OSes, including macOS, have a non-standard length field
right after sun_family.

Not including space for it in UnixSocketAddr.length breaks from_raw()
and always including it is probably a good idea.
  • Loading branch information
tormol committed Oct 15, 2023
1 parent 45d6139 commit da6d387
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl UnixSocketAddr {
let mut addr: sockaddr_un = unsafe { mem::zeroed() };
addr.sun_family = AF_UNIX as sa_family_t;
UnixSocketAddr {
len: mem::size_of::<sa_family_t>() as socklen_t,
len: path_offset(),
addr,
}
}
Expand Down Expand Up @@ -672,7 +672,7 @@ impl UnixSocketAddr {
} else if addr.is_null() {
Err(io::Error::new(ErrorKind::InvalidInput, "addr is NULL"))
} else if len < path_offset() {
Err(io::Error::new(ErrorKind::InvalidInput, "address length is too low"))
Err(io::Error::new(ErrorKind::InvalidInput, "address length is too short"))
} else if len > mem::size_of::<sockaddr_un>() as socklen_t {
Err(io::Error::new(ErrorKind::InvalidInput, TOO_LONG_DESC))
} else if (&*addr).sa_family != AF_UNIX as sa_family_t {
Expand Down

0 comments on commit da6d387

Please sign in to comment.