Skip to content

Commit

Permalink
[#500] Truncate ID if provided buffer too small
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Nov 18, 2024
1 parent 6737410 commit 2b22f5e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion iceoryx2-ffi/ffi/src/api/unique_listener_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ unsafe extern "C" fn iox2_unique_listener_id_value(
debug_assert!(bytes.len() <= id_length, "id_length is too small");

unsafe {
std::ptr::copy_nonoverlapping(bytes.as_ptr(), id_ptr, id_length);
std::ptr::copy_nonoverlapping(
bytes.as_ptr(),
id_ptr,
std::cmp::min(bytes.len(), id_length),
);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion iceoryx2-ffi/ffi/src/api/unique_notifier_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ unsafe extern "C" fn iox2_unique_notifier_id_value(
debug_assert!(bytes.len() <= id_length, "id_length is too small");

unsafe {
std::ptr::copy_nonoverlapping(bytes.as_ptr(), id_ptr, id_length);
std::ptr::copy_nonoverlapping(
bytes.as_ptr(),
id_ptr,
std::cmp::min(bytes.len(), id_length),
);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion iceoryx2-ffi/ffi/src/api/unique_publisher_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ unsafe extern "C" fn iox2_unique_publisher_id_value(
debug_assert!(bytes.len() <= id_length, "id_length is too small");

unsafe {
std::ptr::copy_nonoverlapping(bytes.as_ptr(), id_ptr, id_length);
std::ptr::copy_nonoverlapping(
bytes.as_ptr(),
id_ptr,
std::cmp::min(bytes.len(), id_length),
);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion iceoryx2-ffi/ffi/src/api/unique_subscriber_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ unsafe extern "C" fn iox2_unique_subscriber_id_value(
debug_assert!(bytes.len() <= id_length, "id_length is too small");

unsafe {
std::ptr::copy_nonoverlapping(bytes.as_ptr(), id_ptr, id_length);
std::ptr::copy_nonoverlapping(
bytes.as_ptr(),
id_ptr,
std::cmp::min(bytes.len(), id_length),
);
}
}
}
Expand Down

0 comments on commit 2b22f5e

Please sign in to comment.