You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use libafl_bolts::shmem::{ShMemas _,ShMemProvideras _};fnmain(){letmut prov = libafl_bolts::shmem::MmapShMemProvider::default();let shmem = prov.new_on_shmem([0x01u8;256]).unwrap();let v_ptr = shmem.as_ptr_of::<Vec<u8>>().unwrap();let v = unsafe{(*v_ptr).clone()};println!("{}", v[5]);}
This results in an assertion failure in std (though it could easily also result in a segfault, depending on your machine):
cargo -q run -r
memory allocation of 72340172838076673 bytes failed
zsh: abort (core dumped) cargo -q run -r
The problem is that the type passed to ShMem::as_ptr_of is different from that passed to ShMemProvider::new_on_shmem. In this trivial example, this is easy to see, but one can certainly imagine a larger program where the construction- and use-sites are further away and drift out of sync.
You might say that this isn't that big of a deal, because it requires dereferencing a raw pointer, which is unsafe. In particular, doing so requires you to ensure that there is a valid value of the pointer's type at that address. I would argue that this interface is unnecessarily flexible, and makes it too easy to do the wrong thing without realizing it.
One easy enhancement would be to add a typed wrapper around ShMem:
(I would advocate against impl DerefMut<Target = T> for TypedShMem<S, T> due to #2807.) This retains all of the flexibility of the current approach, while making it easier for the type system to nudge users in the right direction.
This is just a suggestion, feel free to close if you disagree with my reasoning!
The text was updated successfully, but these errors were encountered:
Consider the following program:
This results in an assertion failure in
std
(though it could easily also result in a segfault, depending on your machine):The problem is that the type passed to
ShMem::as_ptr_of
is different from that passed toShMemProvider::new_on_shmem
. In this trivial example, this is easy to see, but one can certainly imagine a larger program where the construction- and use-sites are further away and drift out of sync.You might say that this isn't that big of a deal, because it requires dereferencing a raw pointer, which is
unsafe
. In particular, doing so requires you to ensure that there is a valid value of the pointer's type at that address. I would argue that this interface is unnecessarily flexible, and makes it too easy to do the wrong thing without realizing it.One easy enhancement would be to add a typed wrapper around
ShMem
:(I would advocate against
impl DerefMut<Target = T> for TypedShMem<S, T>
due to #2807.) This retains all of the flexibility of the current approach, while making it easier for the type system to nudge users in the right direction.This is just a suggestion, feel free to close if you disagree with my reasoning!
The text was updated successfully, but these errors were encountered: