From 24d47355e177ff615de36eef49ad825c91dff7ef Mon Sep 17 00:00:00 2001 From: Frederick Mayle Date: Fri, 13 Sep 2024 11:45:42 -0700 Subject: [PATCH] fix off-by-one error in range check of Backlog::new --- src/sys/socket/mod.rs | 2 +- test/sys/test_socket.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 99b47a5905..d55ce3aeff 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -2190,7 +2190,7 @@ impl Backlog { let val = val.into(); - if !(MIN..Self::MAXCONN.0).contains(&val) { + if !(MIN..=Self::MAXCONN.0).contains(&val) { return Err(Errno::EINVAL); } diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index dae766d0aa..93aa606822 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1695,6 +1695,13 @@ pub fn test_named_unixdomain() { assert_eq!(&buf[..], b"hello"); } +#[test] +pub fn test_listen_maxbacklog() { + use nix::sys::socket::Backlog; + + assert!(Backlog::new(libc::SOMAXCONN).is_ok()); +} + #[test] pub fn test_listen_wrongbacklog() { use nix::sys::socket::Backlog;