From 5b779448ab02c60a42e70beee4d2d6f49a5376ec Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Sun, 13 Jan 2019 09:30:37 -0700
Subject: [PATCH] Add IOV_MAX

---
 src/header/sys_uio/mod.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/header/sys_uio/mod.rs b/src/header/sys_uio/mod.rs
index d53c99772..3d137276c 100644
--- a/src/header/sys_uio/mod.rs
+++ b/src/header/sys_uio/mod.rs
@@ -7,6 +7,8 @@ use header::{errno, unistd};
 use platform;
 use platform::types::*;
 
+pub const IOV_MAX: c_int = 1024;
+
 #[repr(C)]
 pub struct iovec {
     iov_base: *mut c_void,
@@ -41,7 +43,7 @@ unsafe fn scatter(iovs: &[iovec], vec: Vec<u8>) {
 
 #[no_mangle]
 pub unsafe extern "C" fn readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
-    if iovcnt < 0 {
+    if iovcnt < 0 || iovcnt > IOV_MAX {
         platform::errno = errno::EINVAL;
         return -1;
     }
@@ -58,7 +60,7 @@ pub unsafe extern "C" fn readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> s
 
 #[no_mangle]
 pub unsafe extern "C" fn writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
-    if iovcnt < 0 {
+    if iovcnt < 0 || iovcnt > IOV_MAX {
         platform::errno = errno::EINVAL;
         return -1;
     }
-- 
GitLab