From 8ae118dc0a9115c6a2783fd42a236d54fab15417 Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 18 Aug 2024 13:36:56 +0800 Subject: [PATCH] Move the maxevents.try_into().unwrap() after value check --- src/tools/miri/src/shims/unix/linux/epoll.rs | 12 +++++++----- src/tools/miri/tests/pass-dep/libc/libc-epoll.rs | 5 ++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/tools/miri/src/shims/unix/linux/epoll.rs b/src/tools/miri/src/shims/unix/linux/epoll.rs index c69a2ac216e..9ee2ad96257 100644 --- a/src/tools/miri/src/shims/unix/linux/epoll.rs +++ b/src/tools/miri/src/shims/unix/linux/epoll.rs @@ -403,18 +403,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let epfd = this.read_scalar(epfd)?.to_i32()?; let maxevents = this.read_scalar(maxevents)?.to_i32()?; - let event = this.deref_pointer_as( - events_op, - this.libc_array_ty_layout("epoll_event", maxevents.try_into().unwrap()), - )?; let timeout = this.read_scalar(timeout)?.to_i32()?; - if epfd <= 0 || maxevents <= 0 { let einval = this.eval_libc("EINVAL"); this.set_last_error(einval)?; return Ok(Scalar::from_i32(-1)); } + // This needs to come after the maxevents value check, or else maxevents.try_into().unwrap() + // will fail. + let event = this.deref_pointer_as( + events_op, + this.libc_array_ty_layout("epoll_event", maxevents.try_into().unwrap()), + )?; + // FIXME: Implement blocking support if timeout != 0 { throw_unsup_format!("epoll_wait: timeout value can only be 0"); diff --git a/src/tools/miri/tests/pass-dep/libc/libc-epoll.rs b/src/tools/miri/tests/pass-dep/libc/libc-epoll.rs index eb742f2ccfb..773204c4947 100644 --- a/src/tools/miri/tests/pass-dep/libc/libc-epoll.rs +++ b/src/tools/miri/tests/pass-dep/libc/libc-epoll.rs @@ -19,7 +19,7 @@ fn main() { test_epoll_ctl_del(); test_pointer(); test_two_same_fd_in_same_epoll_instance(); - test_epoll_wait_less_maxevent_zero(); + test_epoll_wait_maxevent_zero(); } // Using `as` cast since `EPOLLET` wraps around @@ -530,8 +530,7 @@ fn test_no_notification_for_unregister_flag() { check_epoll_wait::<8>(epfd, &[(expected_event, expected_value)]); } - -fn test_epoll_wait_less_maxevent_zero() { +fn test_epoll_wait_maxevent_zero() { // Create an epoll instance. let epfd = unsafe { libc::epoll_create1(0) }; assert_ne!(epfd, -1);