@@ -402,18 +402,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
402402 let this = self . eval_context_mut ( ) ;
403403
404404 let epfd = this. read_scalar ( epfd) ?. to_i32 ( ) ?;
405+ let events = this. read_immediate ( events_op) ?;
405406 let maxevents = this. read_scalar ( maxevents) ?. to_i32 ( ) ?;
406- let event = this. deref_pointer_as (
407- events_op,
408- this. libc_array_ty_layout ( "epoll_event" , maxevents. try_into ( ) . unwrap ( ) ) ,
409- ) ?;
410407 let timeout = this. read_scalar ( timeout) ?. to_i32 ( ) ?;
411408
412- if epfd <= 0 {
409+ if epfd <= 0 || maxevents <= 0 {
413410 let einval = this. eval_libc ( "EINVAL" ) ;
414411 this. set_last_error ( einval) ?;
415412 return Ok ( Scalar :: from_i32 ( -1 ) ) ;
416413 }
414+
415+ // This needs to come after the maxevents value check, or else maxevents.try_into().unwrap()
416+ // will fail.
417+ let events = this. deref_pointer_as (
418+ & events,
419+ this. libc_array_ty_layout ( "epoll_event" , maxevents. try_into ( ) . unwrap ( ) ) ,
420+ ) ?;
421+
417422 // FIXME: Implement blocking support
418423 if timeout != 0 {
419424 throw_unsup_format ! ( "epoll_wait: timeout value can only be 0" ) ;
@@ -429,7 +434,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
429434 let ready_list = epoll_file_description. get_ready_list ( ) ;
430435 let mut ready_list = ready_list. borrow_mut ( ) ;
431436 let mut num_of_events: i32 = 0 ;
432- let mut array_iter = this. project_array_fields ( & event ) ?;
437+ let mut array_iter = this. project_array_fields ( & events ) ?;
433438
434439 while let Some ( ( epoll_key, epoll_return) ) = ready_list. pop_first ( ) {
435440 // If the file description is fully close, the entry for corresponding FdID in the
0 commit comments