Skip to content

Commit c0e799d

Browse files
committed
Set EINVAL for epoll_wait maxevent value 0
1 parent 8821108 commit c0e799d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/tools/miri/src/shims/unix/linux/epoll.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
409409
)?;
410410
let timeout = this.read_scalar(timeout)?.to_i32()?;
411411

412-
if epfd <= 0 {
412+
if epfd <= 0 || maxevents <= 0 {
413413
let einval = this.eval_libc("EINVAL");
414414
this.set_last_error(einval)?;
415415
return Ok(Scalar::from_i32(-1));
416416
}
417+
417418
// FIXME: Implement blocking support
418419
if timeout != 0 {
419420
throw_unsup_format!("epoll_wait: timeout value can only be 0");

src/tools/miri/tests/pass-dep/libc/libc-epoll.rs

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() {
1919
test_epoll_ctl_del();
2020
test_pointer();
2121
test_two_same_fd_in_same_epoll_instance();
22+
test_epoll_wait_less_maxevent_zero();
2223
}
2324

2425
// Using `as` cast since `EPOLLET` wraps around
@@ -528,3 +529,17 @@ fn test_no_notification_for_unregister_flag() {
528529
let expected_value = u64::try_from(fds[0]).unwrap();
529530
check_epoll_wait::<8>(epfd, &[(expected_event, expected_value)]);
530531
}
532+
533+
534+
fn test_epoll_wait_less_maxevent_zero() {
535+
// Create an epoll instance.
536+
let epfd = unsafe { libc::epoll_create1(0) };
537+
assert_ne!(epfd, -1);
538+
// It is ok to use uninitialised pointer here because it will error out before the
539+
// pointer actually get accessed.
540+
let array_ptr = MaybeUninit::<libc::epoll_event>::uninit().as_mut_ptr();
541+
let res = unsafe { libc::epoll_wait(epfd, array_ptr, 0, 0) };
542+
let e = std::io::Error::last_os_error();
543+
assert_eq!(e.raw_os_error(), Some(libc::EINVAL));
544+
assert_eq!(res, -1);
545+
}

0 commit comments

Comments
 (0)