Skip to content

Commit

Permalink
Fix recvmsg() on abstract unix sockets
Browse files Browse the repository at this point in the history
This case was just not implemented at all. Abstract unix sockets are not
null-terminated and are indicated by sun_path beginning with a null
byte.

Fixes: bytecodealliance#660
Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed May 6, 2023
1 parent 93f94e0 commit d7f22fd
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/backend/linux_raw/net/read_sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,31 @@ pub(crate) unsafe fn read_sockaddr_os(storage: *const c::sockaddr, len: usize) -
SocketAddrAny::Unix(SocketAddrUnix::new(&[][..]).unwrap())
} else {
let decode = *storage.cast::<c::sockaddr_un>();
assert_eq!(
decode.sun_path[len - 1 - offsetof_sun_path],
b'\0' as c::c_char
);
SocketAddrAny::Unix(
SocketAddrUnix::new(
decode.sun_path[..len - 1 - offsetof_sun_path]
.iter()
.map(|c| *c as u8)
.collect::<Vec<u8>>(),
if decode.sun_path[0] == 0 {
SocketAddrAny::Unix(
SocketAddrUnix::new_abstract_name(
&decode.sun_path[1..len - offsetof_sun_path]
.iter()
.map(|c| *c as u8)
.collect::<Vec<u8>>(),
)
.unwrap(),
)
} else {
assert_eq!(
decode.sun_path[len - 1 - offsetof_sun_path],
b'\0' as c::c_char
);
SocketAddrAny::Unix(
SocketAddrUnix::new(
decode.sun_path[..len - 1 - offsetof_sun_path]
.iter()
.map(|c| *c as u8)
.collect::<Vec<u8>>(),
)
.unwrap(),
)
.unwrap(),
)
}
}
}
other => unimplemented!("{:?}", other),
Expand Down

0 comments on commit d7f22fd

Please sign in to comment.