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 user after free in MacOS select() #359

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
9 changes: 5 additions & 4 deletions src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ fn select(
MACH_PORT_NULL,
) {
MACH_RCV_TOO_LARGE => {
let max_trailer_size =
mem::size_of::<mach_sys::mach_msg_max_trailer_t>() as mach_sys::mach_msg_size_t;
// the actual size gets written into msgh_size by the kernel
let mut actual_size = (*message).header.msgh_size + max_trailer_size;
loop {
// the actual size gets written into msgh_size by the kernel
let max_trailer_size = mem::size_of::<mach_sys::mach_msg_max_trailer_t>()
as mach_sys::mach_msg_size_t;
let actual_size = (*message).header.msgh_size + max_trailer_size;
allocated_buffer = Some(libc::malloc(actual_size as size_t));
setup_receive_buffer(
slice::from_raw_parts_mut(
Expand All @@ -748,6 +748,7 @@ fn select(
) {
MACH_MSG_SUCCESS => break,
MACH_RCV_TOO_LARGE => {
actual_size = (*message).header.msgh_size + max_trailer_size;
libc::free(allocated_buffer.unwrap() as *mut _);
continue;
},
Expand Down