Skip to content

Commit

Permalink
Avoid UB due to uninitialized memory in max_stack_size
Browse files Browse the repository at this point in the history
  • Loading branch information
wackbyte authored and zonyitoo committed Apr 5, 2023
1 parent f582050 commit efbaf19
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,9 @@ pub fn max_stack_size() -> usize {
let mut ret = PAGE_SIZE.load(Ordering::Relaxed);

if ret == 0 {
let mut limit;
let limitret;

unsafe {
limit = mem::MaybeUninit::uninit().assume_init();
limitret = libc::getrlimit(libc::RLIMIT_STACK, &mut limit);
}
let mut limit = mem::MaybeUninit::uninit();
let limitret = unsafe { libc::getrlimit(libc::RLIMIT_STACK, limit.as_mut_ptr()) };
let limit = unsafe { limit.assume_init() };

if limitret == 0 {
ret = if limit.rlim_max == libc::RLIM_INFINITY
Expand Down

0 comments on commit efbaf19

Please sign in to comment.