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

OpenBSD socket address is padded with zeroes #116523

Closed
notgull opened this issue Oct 7, 2023 · 2 comments · Fixed by #123779
Closed

OpenBSD socket address is padded with zeroes #116523

notgull opened this issue Oct 7, 2023 · 2 comments · Fixed by #123779
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-openbsd Operating system: OpenBSD T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@notgull
Copy link

notgull commented Oct 7, 2023

I tried this code on my Linux machine:

use std::os::unix::net::UnixListener;

fn main() {
    let listener = UnixListener::bind("/tmp/rust-uds.sock").unwrap();
    println!("{:?}", listener.local_addr().unwrap());
}

I got this output:

"/tmp/rust-uds.sock" (pathname)

However, on OpenBSD 7, I got this output:

"/tmp/rust-uds.sock\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" (pathname)

I expected the output to be the same as Linux: not padded with zeroes like this.

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.63.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-openbsd
release: 1.63.0
LLVM version: 13.0.0
@notgull notgull added the C-bug Category: This is a bug. label Oct 7, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 7, 2023
@the8472 the8472 added O-openbsd Operating system: OpenBSD T-libs Relevant to the library team, which will review and decide on the PR/issue. A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 8, 2023
@notgull
Copy link
Author

notgull commented Nov 27, 2023

This is an OpenBSD bug. I've reported it here: https://marc.info/?l=openbsd-bugs&m=170105481926736&w=2

Still, we should work around it in the standard library.

@cjeker
Copy link

cjeker commented Nov 28, 2023

Just to be clear, this is not an OpenBSD bug. OpenBSD decided to return always the full struct sockaddr_un.
This is all within the specification of getsockname imposed by POSIX.
The embedded path sun_path inside struct sockaddr_un is always a valid C string (NUL terminated).
There is therefor no need to look at the address_len argument as long as the passed sockaddr buffer is at least sizeof(struct sockaddr_un) bytes. Developers are highly encouraged to use struct sockaddr_storage to ensure there is no clipping. The reason for this behavior is to reduce the risk of bugs because of the scary getsockname spec.

semarie added a commit to semarie/rust that referenced this issue Apr 11, 2024
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
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 14, 2024
…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
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 14, 2024
…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
@bors bors closed this as completed in 7aaad6b Apr 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 14, 2024
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
TheBearodactyl pushed a commit to TheBearodactyl/confusing-rust that referenced this issue Apr 15, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-openbsd Operating system: OpenBSD T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants