---
 hurd/fd-read.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/hurd/fd-read.c b/hurd/fd-read.c
index 7f4833d8..cd102453 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,25 @@ _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 rbytes;
+
+  if (*nbytes > INT32_MAX)
+    rbytes = INT32_MAX;
+  else
+    rbytes = *nbytes;
 
   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);
-- 
2.47.3


Reply via email to