Skip to content

Commit a0869f9

Browse files
authored
fix off-by-one error in range check of Backlog::new (#2500)
1 parent b6f9cc3 commit a0869f9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/sys/socket/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@ impl Backlog {
21902190

21912191
let val = val.into();
21922192

2193-
if !(MIN..Self::MAXCONN.0).contains(&val) {
2193+
if !(MIN..=Self::MAXCONN.0).contains(&val) {
21942194
return Err(Errno::EINVAL);
21952195
}
21962196

test/sys/test_socket.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,13 @@ pub fn test_named_unixdomain() {
16951695
assert_eq!(&buf[..], b"hello");
16961696
}
16971697

1698+
#[test]
1699+
pub fn test_listen_maxbacklog() {
1700+
use nix::sys::socket::Backlog;
1701+
1702+
assert!(Backlog::new(libc::SOMAXCONN).is_ok());
1703+
}
1704+
16981705
#[test]
16991706
pub fn test_listen_wrongbacklog() {
17001707
use nix::sys::socket::Backlog;

0 commit comments

Comments
 (0)