diff options
| author | bors <bors@rust-lang.org> | 2024-08-22 08:54:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-22 08:54:26 +0000 |
| commit | 695a4f918a18a73f5f2f100a9448318891f6f648 (patch) | |
| tree | 2b5f595ed4379e8a9fc0af5d8a23695dd77b6c06 | |
| parent | 41c65e6350dd0958e810ce8b45b6921ec8a3c098 (diff) | |
| parent | fbdc191fdc71faa65f38c35c7b3d97ba992fa9a7 (diff) | |
| download | rust-695a4f918a18a73f5f2f100a9448318891f6f648.tar.gz rust-695a4f918a18a73f5f2f100a9448318891f6f648.zip | |
Auto merge of #3832 - RalfJung:epoll-test, r=oli-obk
epoll test: avoid some subtly dangling pointers Turns out `let data = MaybeUninit::<u64>::uninit().as_ptr();` is a dangling pointer, the memory gets freed at the end of that line. For these cases we don't care as we don't actually access the pointer, but let's not do such subtle things.
| -rw-r--r-- | src/tools/miri/tests/pass-dep/libc/libc-epoll.rs | 28 |
1 files 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 e28cafd3c28..052ce73de23 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::<u64>::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::<libc::epoll_event>::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::<libc::epoll_event>(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)); |
