diff --git a/hurd/fd-read.c b/hurd/fd-read.c index 7ce5d5bde1..e492c3288b 100644 --- a/hurd/fd-read.c +++ b/hurd/fd-read.c @@ -38,13 +38,15 @@ _hurd_fd_read (struct hurd_fd *fd, void *buf, size_t *nbytes, loff_t offset) 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 (data != buf) + __vm_deallocate (__mach_task_self (), (vm_address_t) data, nread); + return EGRATUITOUS; + } + if (data != buf) { - if (nread > *nbytes) /* Sanity check for bogus server. */ - { - __vm_deallocate (__mach_task_self (), (vm_address_t) data, nread); - return EGRATUITOUS; - } memcpy (buf, data, nread); __vm_deallocate (__mach_task_self (), (vm_address_t) data, nread); } diff --git a/hurd/fd-write.c b/hurd/fd-write.c index 797880756b..2f070c5c5a 100644 --- a/hurd/fd-write.c +++ b/hurd/fd-write.c @@ -34,9 +34,13 @@ _hurd_fd_write (struct hurd_fd *fd, } err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty, writefd)); + if (err) + return err; - if (! err) - *nbytes = wrote; + if (__glibc_unlikely (wrote > *nbytes)) /* Sanity check for bogus server. */ + return EGRATUITOUS; - return err; + *nbytes = wrote; + + return 0; }