Skip to content

Commit

Permalink
Eliminate potential panic in sys_fill_exact (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Jan 27, 2023
1 parent 6536b9e commit 9ceb7e5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/util_libc.rs
Expand Up @@ -8,6 +8,7 @@
#![allow(dead_code)]
use crate::Error;
use core::{
cmp::min,
mem::MaybeUninit,
num::NonZeroU32,
ptr::NonNull,
Expand Down Expand Up @@ -78,7 +79,8 @@ pub fn sys_fill_exact(
} else {
// We don't check for EOF (ret = 0) as the data we are reading
// should be an infinite stream of random bytes.
buf = &mut buf[(res as usize)..];
let len = min(res as usize, buf.len());
buf = &mut buf[len..];
}
}
Ok(())
Expand Down

0 comments on commit 9ceb7e5

Please sign in to comment.