mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add integer overflow check
This commit is contained in:
parent
e1084052a7
commit
3dfab6fb64
@ -72,7 +72,15 @@ fn add_to_ancillary_data<T: Clone>(
|
||||
cmsg_level: libc::c_int,
|
||||
cmsg_type: libc::c_int,
|
||||
) -> bool {
|
||||
let len = (source.len() * size_of::<T>()) as u32;
|
||||
let len = if let Some(len) = source.len().checked_mul(size_of::<T>()) {
|
||||
if let Ok(len) = u32::try_from(len) {
|
||||
len
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
|
||||
unsafe {
|
||||
let additional_space = libc::CMSG_SPACE(len) as usize;
|
||||
|
Loading…
Reference in New Issue
Block a user