Skip to content

Commit 9ceb7e5

Browse files
authored
Eliminate potential panic in sys_fill_exact (#334)
1 parent 6536b9e commit 9ceb7e5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/util_libc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![allow(dead_code)]
99
use crate::Error;
1010
use core::{
11+
cmp::min,
1112
mem::MaybeUninit,
1213
num::NonZeroU32,
1314
ptr::NonNull,
@@ -78,7 +79,8 @@ pub fn sys_fill_exact(
7879
} else {
7980
// We don't check for EOF (ret = 0) as the data we are reading
8081
// should be an infinite stream of random bytes.
81-
buf = &mut buf[(res as usize)..];
82+
let len = min(res as usize, buf.len());
83+
buf = &mut buf[len..];
8284
}
8385
}
8486
Ok(())

0 commit comments

Comments
 (0)