-
Notifications
You must be signed in to change notification settings - Fork 689
Refactor UnixAddr #1618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor UnixAddr #1618
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ use cfg_if::cfg_if; | |
use crate::{Result, errno::Errno}; | ||
use libc::{self, c_void, c_int, iovec, socklen_t, size_t, | ||
CMSG_FIRSTHDR, CMSG_NXTHDR, CMSG_DATA, CMSG_LEN}; | ||
use memoffset::offset_of; | ||
use std::convert::TryInto; | ||
use std::{mem, ptr, slice}; | ||
use std::os::unix::io::RawFd; | ||
#[cfg(target_os = "linux")] | ||
|
@@ -1934,10 +1934,10 @@ pub fn sockaddr_storage_to_addr( | |
Ok(SockAddr::Inet(InetAddr::V6(sin6))) | ||
} | ||
libc::AF_UNIX => { | ||
let pathlen = len - offset_of!(sockaddr_un, sun_path); | ||
unsafe { | ||
let sun = *(addr as *const _ as *const sockaddr_un); | ||
Ok(SockAddr::Unix(UnixAddr::from_raw_parts(sun, pathlen))) | ||
let sun_len = len.try_into().unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unwrapping here makes me a little concerned, but I'm not familiar with the previous behavior. Should we return an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unwrap is guaranteed to pass, because of the assertion on line 1914. |
||
Ok(SockAddr::Unix(UnixAddr::from_raw_parts(sun, sun_len))) | ||
} | ||
} | ||
#[cfg(any(target_os = "android", target_os = "linux"))] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you're using both
NUL
andnul
forb'\0'
. Pick one.