Skip to content

Commit 2dd8775

Browse files
committed
Add assert! to prevent reading past the end of a buffer.
1 parent de2f15a commit 2dd8775

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/unix_term.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ fn read_single_char(fd: i32) -> io::Result<Option<char>> {
183183
// If successful, return the number of bytes read.
184184
// Will return an error if nothing was read, i.e when called at end of file.
185185
fn read_bytes(fd: i32, buf: &mut [u8], count: u8) -> io::Result<u8> {
186+
assert!((count as usize) <= buf.len()); // Safety precondition - prevent reading past end of buffer.
186187
let read = unsafe { libc::read(fd, buf.as_mut_ptr() as *mut _, count as usize) };
187188
if read < 0 {
188189
Err(io::Error::last_os_error())

0 commit comments

Comments
 (0)