Skip to content

Commit fa21a30

Browse files
committed
fix(shadowsocks): check mptcp socket() return value
1 parent c31719a commit fa21a30

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

crates/shadowsocks/src/net/sys/unix/bsd/macos.rs

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ impl TcpStream {
5454

5555
let socket = unsafe {
5656
let fd = libc::socket(AF_MULTIPATH, libc::SOCK_STREAM, libc::IPPROTO_TCP);
57+
if fd < 0 {
58+
let err = io::Error::last_os_error();
59+
return Err(err);
60+
}
5761
let socket = Socket::from_raw_fd(fd);
5862
socket.set_nonblocking(true)?;
5963
TcpSocket::from_raw_fd(socket.into_raw_fd())

crates/shadowsocks/src/net/sys/unix/linux/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,18 @@ pub fn set_tcp_fastopen<S: AsRawFd>(socket: &S) -> io::Result<()> {
213213
}
214214

215215
fn create_mptcp_socket(bind_addr: &SocketAddr) -> io::Result<TcpSocket> {
216+
// https://www.kernel.org/doc/html/next/networking/mptcp.html
217+
216218
unsafe {
217219
let family = match bind_addr {
218220
SocketAddr::V4(..) => libc::AF_INET,
219221
SocketAddr::V6(..) => libc::AF_INET6,
220222
};
221223
let fd = libc::socket(family, libc::SOCK_STREAM, libc::IPPROTO_MPTCP);
224+
if fd < 0 {
225+
let err = io::Error::last_os_error();
226+
return Err(err);
227+
}
222228
let socket = Socket::from_raw_fd(fd);
223229
socket.set_nonblocking(true)?;
224230
Ok(TcpSocket::from_raw_fd(socket.into_raw_fd()))

0 commit comments

Comments
 (0)