`SockAddr::as_unix` panics on a path with an interior null byte

Open Beginner friendly
#681 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@omrzk is already working on this.

Since Nov 2, 2026.

  • #682 by @omrzk — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
networking

Research direction

Find SockAddr::as_unix in the socket2 source (likely src/lib.rs or src/unix.rs). Read the method and SockAddr::unix to see the length vs null-byte check. Add a test with "a\0b", then change from_pathname(path).unwrap() to ok() so it returns None. Done when the example no longer panics.

Written by the indexing model from the issue text.

Description

SockAddr::as_unix panics from safe code:

let addr = socket2::SockAddr::unix("a\0b").unwrap();
let _ = addr.as_unix(); // panics

results in

called `Result::unwrap()` on an `Err` value: paths must not contain interior null bytes

as_unix assumes that any path from as_pathname can be represented by the standard library, and unwraps:

let path = self.as_pathname()?;
// SAFETY: we can represent this as a valid pathname, then so can the standard library.
Some(std::os::unix::net::SocketAddr::from_pathname(path).unwrap())

But SockAddr::unix only checks the length of the path, and from_pathname also rejects an interior null.

Dominant language
Rust
Stars
885
Forks
328
Avg merge
6d 12h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/socket2

All issues in rust-lang/socket2

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.