@@ -402,18 +402,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
402
402
let this = self . eval_context_mut ( ) ;
403
403
404
404
let epfd = this. read_scalar ( epfd) ?. to_i32 ( ) ?;
405
+ let events = this. read_immediate ( events_op) ?;
405
406
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
- ) ?;
410
407
let timeout = this. read_scalar ( timeout) ?. to_i32 ( ) ?;
411
408
412
- if epfd <= 0 {
409
+ if epfd <= 0 || maxevents <= 0 {
413
410
let einval = this. eval_libc ( "EINVAL" ) ;
414
411
this. set_last_error ( einval) ?;
415
412
return Ok ( Scalar :: from_i32 ( -1 ) ) ;
416
413
}
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
+
417
422
// FIXME: Implement blocking support
418
423
if timeout != 0 {
419
424
throw_unsup_format ! ( "epoll_wait: timeout value can only be 0" ) ;
@@ -429,7 +434,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
429
434
let ready_list = epoll_file_description. get_ready_list ( ) ;
430
435
let mut ready_list = ready_list. borrow_mut ( ) ;
431
436
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 ) ?;
433
438
434
439
while let Some ( ( epoll_key, epoll_return) ) = ready_list. pop_first ( ) {
435
440
// If the file description is fully close, the entry for corresponding FdID in the
0 commit comments