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

net: fix handling of leading zero byte in from_abstract_name #6838

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tokio/src/net/unix/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl UnixListener {
let addr = {
let os_str_bytes = path.as_ref().as_os_str().as_bytes();
if os_str_bytes.starts_with(b"\0") {
StdSocketAddr::from_abstract_name(os_str_bytes)?
StdSocketAddr::from_abstract_name(&os_str_bytes[1..])?
} else {
StdSocketAddr::from_pathname(path)?
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl UnixStream {
let addr = {
let os_str_bytes = path.as_ref().as_os_str().as_bytes();
if os_str_bytes.starts_with(b"\0") {
StdSocketAddr::from_abstract_name(os_str_bytes)?
StdSocketAddr::from_abstract_name(&os_str_bytes[1..])?
} else {
StdSocketAddr::from_pathname(path)?
}
Expand Down
12 changes: 11 additions & 1 deletion tokio/tests/uds_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#![cfg(unix)]

use std::io;
#[cfg(target_os = "android")]
use std::os::android::net::SocketAddrExt;
#[cfg(target_os = "linux")]
use std::os::linux::net::SocketAddrExt;
use std::task::Poll;

use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest};
Expand Down Expand Up @@ -431,5 +435,11 @@ async fn abstract_socket_name() {
let accept = listener.accept();
let connect = UnixStream::connect(&socket_path);

try_join(accept, connect).await.unwrap();
let ((stream, _), _) = try_join(accept, connect).await.unwrap();

let local_addr = stream.into_std().unwrap().local_addr().unwrap();
let abstract_path_name = local_addr.as_abstract_name().unwrap();

// `as_abstract_name` removes leading zero bytes
assert_eq!(abstract_path_name, b"aaa");
}
Loading