Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic in mmap shmem when full_file_name is less than MAX_MMAP_FILENAME_LEN #2536

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions libafl_bolts/src/shmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,11 @@ pub mod unix_shmem {
/// This will *NOT* automatically delete the shmem files, meaning that it's user's responsibility to delete all `/dev/shm/libafl_*` after fuzzing
pub fn new(map_size: usize, rand_id: u32) -> Result<Self, Error> {
unsafe {
let full_file_name = format!("/libafl_{}_{}", process::id(), rand_id);
let mut full_file_name = format!("/libafl_{}_{}", process::id(), rand_id);
full_file_name.truncate(MAX_MMAP_FILENAME_LEN);
let mut filename_path = [0_u8; MAX_MMAP_FILENAME_LEN];
filename_path
.copy_from_slice(&full_file_name.as_bytes()[..MAX_MMAP_FILENAME_LEN]);
filename_path[0..full_file_name.len()]
.copy_from_slice(full_file_name.as_bytes());
filename_path[MAX_MMAP_FILENAME_LEN - 1] = 0; // Null terminate!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should now be be full_file_name.len() right?

log::info!(
"{} Creating shmem {} {:#?}",
Expand Down