From ebc6c0d94cb47cb09f8ed17ad95a6e2ca882f503 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Mon, 24 Mar 2025 15:04:36 -0700 Subject: [PATCH] Change ptr::eq to ptr::addr_eq where semantically more correct (#3105) * Change ptr::eq to ptr::addr_eq where semantically more correct * not needed here? --- libafl_bolts/src/lib.rs | 2 +- libafl_bolts/src/llmp.rs | 5 ++++- libafl_bolts/src/shmem.rs | 14 +++++++------- libafl_frida/src/asan/hook_funcs.rs | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libafl_bolts/src/lib.rs b/libafl_bolts/src/lib.rs index d3204fce8e..b972d85048 100644 --- a/libafl_bolts/src/lib.rs +++ b/libafl_bolts/src/lib.rs @@ -1106,7 +1106,7 @@ mod windows_logging { // Get the handle to standard output let h_stdout: HANDLE = get_stdout_handle(); - if ptr::eq(h_stdout, INVALID_HANDLE_VALUE) { + if ptr::addr_eq(h_stdout, INVALID_HANDLE_VALUE) { eprintln!("Failed to get standard output handle"); return; } diff --git a/libafl_bolts/src/llmp.rs b/libafl_bolts/src/llmp.rs index 3b6867df33..a08baeecd5 100644 --- a/libafl_bolts/src/llmp.rs +++ b/libafl_bolts/src/llmp.rs @@ -1587,7 +1587,10 @@ where unsafe { // log::info!("Sending msg {:?}", msg); - assert!(!ptr::eq(self.last_msg_sent, msg), "Message sent twice!"); + assert!( + !ptr::addr_eq(self.last_msg_sent, msg), + "Message sent twice!" + ); assert!( (*msg).tag != LLMP_TAG_UNSET, "No tag set on message with id {:?}", diff --git a/libafl_bolts/src/shmem.rs b/libafl_bolts/src/shmem.rs index 36013556f1..b7222b3cb5 100644 --- a/libafl_bolts/src/shmem.rs +++ b/libafl_bolts/src/shmem.rs @@ -771,7 +771,7 @@ pub mod unix_shmem { shm_fd, 0, ); - if ptr::eq(map, libc::MAP_FAILED) { + if ptr::addr_eq(map, libc::MAP_FAILED) { close(shm_fd); shm_unlink(filename_path.as_ptr() as *const _); return Err(Error::last_os_error(format!( @@ -845,7 +845,7 @@ pub mod unix_shmem { shm_fd, 0, ); - if ptr::eq(map, libc::MAP_FAILED) { + if ptr::addr_eq(map, libc::MAP_FAILED) { close(shm_fd); return Err(Error::last_os_error(format!( "mmap() failed for map with fd {shm_fd:?}" @@ -1081,7 +1081,7 @@ pub mod unix_shmem { let id_int: i32 = id.into(); let map = shmat(id_int, ptr::null(), 0) as *mut c_uchar; - if ptr::eq(map, ptr::null_mut::().wrapping_sub(1)) { + if ptr::addr_eq(map, ptr::null_mut::().wrapping_sub(1)) { return Err(Error::last_os_error(format!( "Failed to map the shared mapping with id {id_int}" ))); @@ -1250,7 +1250,7 @@ pub mod unix_shmem { fd, 0, ); - if ptr::eq(map, usize::MAX as *mut c_void) { + if ptr::addr_eq(map, usize::MAX as *mut c_void) { close(fd); return Err(Error::unknown( "Failed to map the ashmem mapping".to_string(), @@ -1285,7 +1285,7 @@ pub mod unix_shmem { fd, 0, ); - if ptr::eq(map, usize::MAX as *mut c_void) { + if ptr::addr_eq(map, usize::MAX as *mut c_void) { close(fd); return Err(Error::unknown( "Failed to map the ashmem mapping".to_string(), @@ -1434,7 +1434,7 @@ pub mod unix_shmem { fd, 0, ); - if ptr::eq(map, libc::MAP_FAILED) { + if ptr::addr_eq(map, libc::MAP_FAILED) { close(fd); return Err(Error::unknown( "Failed to map the memfd mapping".to_string(), @@ -1471,7 +1471,7 @@ pub mod unix_shmem { fd, 0, ); - if ptr::eq(map, libc::MAP_FAILED) { + if ptr::addr_eq(map, libc::MAP_FAILED) { return Err(Error::last_os_error(format!( "mmap() failed for map with fd {fd:?}" ))); diff --git a/libafl_frida/src/asan/hook_funcs.rs b/libafl_frida/src/asan/hook_funcs.rs index b40b38e2ac..61a18c6335 100644 --- a/libafl_frida/src/asan/hook_funcs.rs +++ b/libafl_frida/src/asan/hook_funcs.rs @@ -1608,7 +1608,7 @@ impl AsanRuntime { ) -> *mut c_void { log::trace!("hook_mmap"); let res = original(addr, length, prot, flags, fd, offset); - if !ptr::eq(res, -1_isize as *mut c_void) { + if !ptr::addr_eq(res, ptr::null_mut::().wrapping_sub(1)) { self.allocator_mut() .map_shadow_for_region(res as usize, res as usize + length, true); }