Skip to content

Commit

Permalink
Unrolled build for rust-lang#123779
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#123779 - semarie:notgull-openbsd-socket, r=Mark-Simulacrum

OpenBSD fix long socket addresses

Original diff from ``@notgull`` in rust-lang#118349, small changes from me.

on OpenBSD, getsockname(2) returns the actual size of the socket address, and  not the len of the content. Figure out the length for ourselves. see https://marc.info/?l=openbsd-bugs&m=170105481926736&w=2

Fixes rust-lang#116523
  • Loading branch information
rust-timer committed Apr 14, 2024
2 parents a3269e9 + 7aaad6b commit b611570
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/std/src/os/unix/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ impl SocketAddr {
addr: libc::sockaddr_un,
mut len: libc::socklen_t,
) -> io::Result<SocketAddr> {
if cfg!(target_os = "openbsd") {
// on OpenBSD, getsockname(2) returns the actual size of the socket address,
// and not the len of the content. Figure out the length for ourselves.
// https://marc.info/?l=openbsd-bugs&m=170105481926736&w=2
let sun_path: &[u8] =
unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&addr.sun_path) };
len = core::slice::memchr::memchr(0, sun_path)
.map_or(len, |new_len| (new_len + sun_path_offset(&addr)) as libc::socklen_t);
}

if len == 0 {
// When there is a datagram from unnamed unix socket
// linux returns zero bytes of address
Expand Down

0 comments on commit b611570

Please sign in to comment.