Skip to content

Commit

Permalink
fix off-by-one error in range check of Backlog::new (nix-rust#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkm3 authored Sep 17, 2024
1 parent b6f9cc3 commit a0869f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions test/sys/test_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a0869f9

Please sign in to comment.