Skip to content

Commit 2bd727e

Browse files
authored
Merge pull request #1893 from hermit-os/socket-proto
fix(socket): accept non-zero proto values
2 parents bfb20bd + c8b212e commit 2bd727e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/syscalls/socket/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,15 @@ pub extern "C" fn sys_socket(domain: i32, type_: i32, protocol: i32) -> i32 {
575575
return -i32::from(Errno::Inval);
576576
};
577577

578-
if protocol != 0 {
578+
let Ok(Ok(proto)) = u8::try_from(protocol).map(Ipproto::try_from) else {
579579
return -i32::from(Errno::Inval);
580+
};
581+
582+
match (sock, proto) {
583+
(_, Ipproto::Ip | Ipproto::Ipv6)
584+
| (Sock::Stream, Ipproto::Tcp)
585+
| (Sock::Dgram, Ipproto::Udp) => {}
586+
(_, _) => return -i32::from(Errno::Inval),
580587
}
581588

582589
#[cfg(feature = "vsock")]

0 commit comments

Comments
 (0)