Skip to content
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

UnixAddr::new_abstract() is using the wrong length #1119

Closed
yshui opened this issue Sep 3, 2019 · 1 comment · Fixed by #1120
Closed

UnixAddr::new_abstract() is using the wrong length #1119

yshui opened this issue Sep 3, 2019 · 1 comment · Fixed by #1120

Comments

@yshui
Copy link
Contributor

yshui commented Sep 3, 2019

nix/src/sys/socket/addr.rs

Lines 549 to 565 in a4a465d

unsafe {
let mut ret = libc::sockaddr_un {
sun_family: AddressFamily::Unix as sa_family_t,
.. mem::zeroed()
};
if path.len() + 1 > ret.sun_path.len() {
return Err(Error::Sys(Errno::ENAMETOOLONG));
}
// Abstract addresses are represented by sun_path[0] ==
// b'\0', so copy starting one byte in.
ptr::copy_nonoverlapping(path.as_ptr(),
ret.sun_path.as_mut_ptr().offset(1) as *mut u8,
path.len());
Ok(UnixAddr(ret, ret.sun_path.len()))

Here, the ret.sun_path.len() should be path.len() + 1

@asomers
Copy link
Member

asomers commented Sep 3, 2019

doh! it looks like you're right. Would you mind submitting a PR to fix it, along with a test that demonstrates the problem?

bors bot added a commit that referenced this issue Sep 4, 2019
1120: Fix length of abstract socket address r=asomers a=yshui

NULL bytes have no special significance in an abstrace address, and the
length of the address is solely decided by the length member. If the
length is set to sun_path.len(), all the NULL bytes will be considered
part of the address.

Tests are updated accordingly.

Closes #1119

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>

Co-authored-by: Yuxuan Shui <yshuiv7@gmail.com>
@bors bors bot closed this as completed in 39d158a Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants