diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2016-09-30 10:53:12 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2016-09-30 10:53:12 +0000 |
commit | d9f7eac08b3d3cde735673f8e8c2be9595a65ca2 (patch) | |
tree | 2dea33a2798d0e395d69cc9f7c3e21a37dd5a678 /sys | |
parent | ee0484bb84cb1f8ce467d72ec4ae27395853978a (diff) |
Make read(2) return EISDIR on directories.
Years ago Theo made read(2) return 0 on directories, instead of dumping
the directory content. Another behavior is allowed as an extension by
POSIX, returning an EISDIR error, as used on a few other systems. This
behavior is deemed more useful as it helps spotting errors. This
implies that it might break some setups.
Ports bulk builds by ajacoutot@ and naddy@, ok millert@ bluhm@ naddy@
deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/vfs_vnops.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 374c069cbc2..cfac17069ea 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_vnops.c,v 1.85 2016/06/19 11:54:33 natano Exp $ */ +/* $OpenBSD: vfs_vnops.c,v 1.86 2016/09/30 10:53:11 jca Exp $ */ /* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */ /* @@ -336,11 +336,13 @@ vn_read(struct file *fp, off_t *poff, struct uio *uio, struct ucred *cred) if (vp->v_type != VCHR && count > LLONG_MAX - *poff) return (EINVAL); + if (vp->v_type == VDIR) + return (EISDIR); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); uio->uio_offset = *poff; - if (vp->v_type != VDIR) - error = VOP_READ(vp, uio, - (fp->f_flag & FNONBLOCK) ? IO_NDELAY : 0, cred); + error = VOP_READ(vp, uio, (fp->f_flag & FNONBLOCK) ? IO_NDELAY : 0, + cred); *poff += count - uio->uio_resid; VOP_UNLOCK(vp, p); return (error); |