From 86c75cc3de973e7d270fac8d4aa9b703e3afb84d Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 3 Feb 2000 01:21:52 +0000 Subject: [PATCH] 2000-02-02 Roland McGrath * sysdeps/mach/hurd/readlink.c (__readlink): Don't clobber original LEN value with io_read result; save it and compare them just in case the server bogusly returns more than we asked for. * sysdeps/mach/hurd/recv.c (recv): Likewise for socket_recv. * sysdeps/mach/hurd/recvfrom.c (recvfrom): Likewise. * hurd/fd-read.c (_hurd_fd_read): Likewise for io_read. Initialize NREAD before the RPC. I think this must only have failed to bomb before because all the servers always return ool data(?). --- hurd/fd-read.c | 5 ++++- sysdeps/mach/hurd/readlink.c | 9 ++++++--- sysdeps/mach/hurd/recv.c | 4 +++- sysdeps/mach/hurd/recvfrom.c | 6 ++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/hurd/fd-read.c b/hurd/fd-read.c index 8bfc03ab8b4..a0191a6de09 100644 --- a/hurd/fd-read.c +++ b/hurd/fd-read.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc. +/* Copyright (C) 1993,94,95,97,2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -35,11 +35,14 @@ _hurd_fd_read (struct hurd_fd *fd, void *buf, size_t *nbytes) } data = buf; + nread = *nbytes; if (err = HURD_FD_PORT_USE (fd, _hurd_ctty_input (port, ctty, readfd))) return err; if (data != buf) { + if (nread > *nbytes) /* Server funny business, shouldn't happen. */ + *nbytes = nread; memcpy (buf, data, nread); __vm_deallocate (__mach_task_self (), (vm_address_t) data, nread); } diff --git a/sysdeps/mach/hurd/readlink.c b/sysdeps/mach/hurd/readlink.c index b79269256fb..86f50f50778 100644 --- a/sysdeps/mach/hurd/readlink.c +++ b/sysdeps/mach/hurd/readlink.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 92, 93, 94, 95, 97 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,93,94,95,97,2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -44,12 +44,15 @@ __readlink (file_name, buf, len) if (S_ISLNK (st.st_mode)) { char *rbuf = buf; + size_t got; - err = __io_read (file, &rbuf, &len, 0, len); + err = __io_read (file, &rbuf, &got, 0, len); + if (got < len) + len = got; if (!err && rbuf != buf) { memcpy (buf, rbuf, len); - __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, len); + __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, got); } } else diff --git a/sysdeps/mach/hurd/recv.c b/sysdeps/mach/hurd/recv.c index 6ae3a6ad8b4..df76e77b5b4 100644 --- a/sysdeps/mach/hurd/recv.c +++ b/sysdeps/mach/hurd/recv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994, 1997 Free Software Foundation, Inc. +/* Copyright (C) 1994,97,2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -56,6 +56,8 @@ recv (fd, buf, n, flags) if (bufp != buf) { + if (nread > n) /* Server funny business, shouldn't happen. */ + nread = n; memcpy (buf, bufp, nread); __vm_deallocate (__mach_task_self (), (vm_address_t) bufp, nread); } diff --git a/sysdeps/mach/hurd/recvfrom.c b/sysdeps/mach/hurd/recvfrom.c index b39528628c4..d4b4deccffe 100644 --- a/sysdeps/mach/hurd/recvfrom.c +++ b/sysdeps/mach/hurd/recvfrom.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994, 1997, 1999 Free Software Foundation, Inc. +/* Copyright (C) 1994,97,99,2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -76,7 +76,7 @@ recvfrom (fd, buf, n, flags, addrarg, addr_len) __mach_port_deallocate (__mach_task_self (), addrport); return __hurd_dfail (fd, err); } - + if (*addr_len > buflen) *addr_len = buflen; @@ -97,6 +97,8 @@ recvfrom (fd, buf, n, flags, addrarg, addr_len) if (bufp != buf) { + if (nread > n) /* Server funny business, shouldn't happen. */ + nread = n; memcpy (buf, bufp, nread); __vm_deallocate (__mach_task_self (), (vm_address_t) bufp, nread); } -- 2.47.2