Skip to content

Commit

Permalink
check limit on the number of scatter/gather elements
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed May 21, 2024
1 parent 17edb13 commit a9b76a0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ struct iovec {
pub iov_len: usize,
}

const IOV_MAX: usize = 1024;

pub(crate) fn init() {
Lazy::force(&SYS);

Expand Down Expand Up @@ -415,6 +417,10 @@ pub unsafe extern "C" fn sys_read(fd: FileDescriptor, buf: *mut u8, len: usize)

#[hermit_macro::system]
pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: usize) -> isize {
if iovcnt > IOV_MAX {
return (-crate::errno::EINVAL).try_into().unwrap();
}

let mut count: isize = 0;
let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt) };

Expand Down Expand Up @@ -455,6 +461,10 @@ pub unsafe extern "C" fn sys_write(fd: FileDescriptor, buf: *const u8, len: usiz

#[hermit_macro::system]
pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcnt: usize) -> isize {
if iovcnt > IOV_MAX {
return (-crate::errno::EINVAL).try_into().unwrap();
}

let mut count: isize = 0;
let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt) };

Expand Down

0 comments on commit a9b76a0

Please sign in to comment.