Skip to content

Commit 1f9837c

Browse files
authored
Detect overflow on nchanges and nevents in kevent. (#558)
The `nchanges` and `nevents` arguments on at least FreeBSD have type `c_int`, so detect and report overflow when converting from `usize`.
1 parent 6c00987 commit 1f9837c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/libc/io/syscalls.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,15 @@ pub(crate) unsafe fn kevent(
469469
ret_c_int(c::kevent(
470470
borrowed_fd(kq),
471471
changelist.as_ptr() as *const _,
472-
changelist.len() as _,
472+
changelist
473+
.len()
474+
.try_into()
475+
.map_err(|_| io::Errno::OVERFLOW)?,
473476
eventlist.as_mut_ptr() as *mut _,
474-
eventlist.len() as _,
477+
eventlist
478+
.len()
479+
.try_into()
480+
.map_err(|_| io::Errno::OVERFLOW)?,
475481
timeout.map_or(core::ptr::null(), |t| t as *const _),
476482
))
477483
}

0 commit comments

Comments
 (0)