---
 hurd/fd-read.c  | 17 ++++++++++++++---
 hurd/fd-write.c | 13 +++++++++++--
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/hurd/fd-read.c b/hurd/fd-read.c
index 7f4833d8..1a667900 100644
--- a/hurd/fd-read.c
+++ b/hurd/fd-read.c
@@ -15,6 +15,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <stdint.h>
 #include <errno.h>
 #include <unistd.h>
 #include <hurd.h>
@@ -27,18 +28,28 @@ _hurd_fd_read (struct hurd_fd *fd, void *buf, size_t 
*nbytes, loff_t offset)
   error_t err;
   char *data;
   mach_msg_type_number_t nread;
+  size_t max;
+  size_t rbytes;
+
+  max = ((size_t) 1 << (sizeof(mach_msg_type_number_t) * 8 - 1)) - 1;
+  rbytes = *nbytes;
+
+  if (rbytes > max)
+    rbytes = max;
+
 
   error_t readfd (io_t port)
     {
-      return __io_read (port, &data, &nread, offset, *nbytes);
+      return __io_read (port, &data, &nread, offset, rbytes);
     }
 
   data = buf;
-  nread = *nbytes;
+  nread = rbytes;
+
   if (err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_input (port, ctty, 
readfd)))
     return err;
 
-  if (__glibc_unlikely (nread > *nbytes))      /* Sanity check for bogus 
server.  */
+  if (__glibc_unlikely (nread > rbytes))       /* Sanity check for bogus 
server.  */
     {
       if (data != buf)
        __vm_deallocate (__mach_task_self (), (vm_address_t) data, nread);
diff --git a/hurd/fd-write.c b/hurd/fd-write.c
index 2dc2eedf..81cc864f 100644
--- a/hurd/fd-write.c
+++ b/hurd/fd-write.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <stdint.h>
 #include <errno.h>
 #include <unistd.h>
 #include <hurd.h>
@@ -27,17 +28,25 @@ _hurd_fd_write (struct hurd_fd *fd,
 {
   error_t err;
   vm_size_t wrote;
+  size_t max; 
+  size_t wbytes;
+
+  max = ((size_t) 1 << (sizeof(mach_msg_type_number_t) * 8 - 1)) - 1;
+  wbytes = *nbytes;
+
+  if (wbytes > max)
+    wbytes = max;
 
   error_t writefd (io_t port)
     {
-      return __io_write (port, buf, *nbytes, offset, &wrote);
+      return __io_write (port, buf, wbytes, offset, &wrote);
     }
 
   err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty, writefd));
   if (err)
     return err;
 
-  if (__glibc_unlikely (wrote > *nbytes))      /* Sanity check for bogus 
server.  */
+  if (__glibc_unlikely (wrote > wbytes))       /* Sanity check for bogus 
server.  */
     return EGRATUITOUS;
 
   *nbytes = wrote;
-- 
2.47.3


Reply via email to