From df40db5ae82b757729c35ad8ff5ac3da7ddf9696 Mon Sep 17 00:00:00 2001 From: Valentin Huber Date: Mon, 10 Jun 2024 17:59:51 +0200 Subject: [PATCH] Fix closing mmap on provider::release_shmem (#2298) --- libafl_bolts/src/shmem.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libafl_bolts/src/shmem.rs b/libafl_bolts/src/shmem.rs index 24f0d79e0c..3be93fdb8c 100644 --- a/libafl_bolts/src/shmem.rs +++ b/libafl_bolts/src/shmem.rs @@ -646,6 +646,7 @@ pub mod unix_shmem { mod default { use alloc::string::ToString; use core::{ + ffi::CStr, ops::{Deref, DerefMut}, ptr, slice, }; @@ -822,6 +823,16 @@ pub mod unix_shmem { ) -> Result { MmapShMem::shmem_from_id_and_size(id, size) } + + fn release_shmem(&mut self, shmem: &mut Self::ShMem) { + let fd = CStr::from_bytes_until_nul(shmem.id().as_array()) + .unwrap() + .to_str() + .unwrap() + .parse() + .unwrap(); + unsafe { close(fd) }; + } } impl ShMem for MmapShMem { @@ -1032,6 +1043,7 @@ pub mod unix_shmem { #[derive(Copy, Clone)] #[repr(C)] + #[allow(non_camel_case_types)] struct ashmem_pin { pub offset: c_uint, pub len: c_uint,