From fbdc191fdc71faa65f38c35c7b3d97ba992fa9a7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 21 Aug 2024 16:16:48 +0200 Subject: [PATCH] epoll test: avoid some subtly dangling pointers --- .../miri/tests/pass-dep/libc/libc-epoll.rs | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) 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 e28cafd3c285b..052ce73de237f 100644 --- a/src/tools/miri/tests/pass-dep/libc/libc-epoll.rs +++ b/src/tools/miri/tests/pass-dep/libc/libc-epoll.rs @@ -1,8 +1,7 @@ //@only-target-linux -#![feature(exposed_provenance)] // Needed for fn test_pointer() +#![feature(strict_provenance)] use std::convert::TryInto; -use std::mem::MaybeUninit; fn main() { test_epoll_socketpair(); @@ -17,7 +16,6 @@ fn main() { test_no_notification_for_unregister_flag(); test_epoll_ctl_mod(); test_epoll_ctl_del(); - test_pointer(); test_two_same_fd_in_same_epoll_instance(); test_epoll_wait_maxevent_zero(); test_socketpair_epollerr(); @@ -261,24 +259,6 @@ fn test_epoll_eventfd() { check_epoll_wait::<8>(epfd, &[(expected_event, expected_value)]); } -fn test_pointer() { - // Create an epoll instance. - let epfd = unsafe { libc::epoll_create1(0) }; - assert_ne!(epfd, -1); - - // Create a socketpair instance. - let mut fds = [-1, -1]; - let res = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) }; - assert_eq!(res, 0); - - // Register fd[1] with EPOLLIN|EPOLLOUT|EPOLLET - let data = MaybeUninit::::uninit().as_ptr(); - let mut ev = - libc::epoll_event { events: EPOLL_IN_OUT_ET, u64: data.expose_provenance() as u64 }; - let res = unsafe { libc::epoll_ctl(epfd, libc::EPOLL_CTL_ADD, fds[1], &mut ev) }; - assert_eq!(res, 0); -} - // When read/write happened on one side of the socketpair, only the other side will be notified. fn test_epoll_socketpair_both_sides() { // Create an epoll instance. @@ -543,9 +523,9 @@ fn test_epoll_wait_maxevent_zero() { // Create an epoll instance. let epfd = unsafe { libc::epoll_create1(0) }; assert_ne!(epfd, -1); - // It is ok to use uninitialised pointer here because it will error out before the - // pointer actually get accessed. - let array_ptr = MaybeUninit::::uninit().as_mut_ptr(); + // It is ok to use a dangling pointer here because it will error out before the + // pointer actually gets accessed. + let array_ptr = std::ptr::without_provenance_mut::(0x100); let res = unsafe { libc::epoll_wait(epfd, array_ptr, 0, 0) }; let e = std::io::Error::last_os_error(); assert_eq!(e.raw_os_error(), Some(libc::EINVAL));