svn commit: r328957 - in head/sys: fs/ext2fs ufs/ufs
Pedro F. Giffuni
pfg at FreeBSD.org
Tue Feb 6 22:38:20 UTC 2018
Author: pfg
Date: Tue Feb 6 22:38:19 2018
New Revision: 328957
URL: https://svnweb.freebsd.org/changeset/base/328957
Log:
{ext2|ufs}_readdir: Avoid setting negative ncookies.
ncookies cannot be negative or the allocator will fail. This should only
happen if a caller is very broken but we can still try to survive the
event.
We should probably also verify for uio_resid > MAXPHYS but in that case
it is not clear that just clipping the ncookies value is an adequate
response.
MFC after: 2 weeks
Modified:
head/sys/fs/ext2fs/ext2_lookup.c
head/sys/ufs/ufs/ufs_vnops.c
Modified: head/sys/fs/ext2fs/ext2_lookup.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_lookup.c Tue Feb 6 22:17:01 2018 (r328956)
+++ head/sys/fs/ext2fs/ext2_lookup.c Tue Feb 6 22:38:19 2018 (r328957)
@@ -153,7 +153,10 @@ ext2_readdir(struct vop_readdir_args *ap)
return (EINVAL);
ip = VTOI(vp);
if (ap->a_ncookies != NULL) {
- ncookies = uio->uio_resid;
+ if (uio->uio_resid < 0)
+ ncookies = 0;
+ else
+ ncookies = uio->uio_resid;
if (uio->uio_offset >= ip->i_size)
ncookies = 0;
else if (ip->i_size - uio->uio_offset < ncookies)
Modified: head/sys/ufs/ufs/ufs_vnops.c
==============================================================================
--- head/sys/ufs/ufs/ufs_vnops.c Tue Feb 6 22:17:01 2018 (r328956)
+++ head/sys/ufs/ufs/ufs_vnops.c Tue Feb 6 22:38:19 2018 (r328957)
@@ -2179,7 +2179,10 @@ ufs_readdir(ap)
if (ip->i_effnlink == 0)
return (0);
if (ap->a_ncookies != NULL) {
- ncookies = uio->uio_resid;
+ if (uio->uio_resid < 0)
+ ncookies = 0;
+ else
+ ncookies = uio->uio_resid;
if (uio->uio_offset >= ip->i_size)
ncookies = 0;
else if (ip->i_size - uio->uio_offset < ncookies)
More information about the svn-src-head
mailing list