summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2016-09-30 10:53:12 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2016-09-30 10:53:12 +0000
commitd9f7eac08b3d3cde735673f8e8c2be9595a65ca2 (patch)
tree2dea33a2798d0e395d69cc9f7c3e21a37dd5a678
parentee0484bb84cb1f8ce467d72ec4ae27395853978a (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@
-rw-r--r--lib/libc/sys/read.210
-rw-r--r--sys/kern/vfs_vnops.c10
2 files changed, 12 insertions, 8 deletions
diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2
index 48e227354ee..07269801fe7 100644
--- a/lib/libc/sys/read.2
+++ b/lib/libc/sys/read.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: read.2,v 1.35 2015/02/05 02:33:09 schwarze Exp $
+.\" $OpenBSD: read.2,v 1.36 2016/09/30 10:53:11 jca Exp $
.\" $NetBSD: read.2,v 1.6 1995/02/27 12:35:47 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)read.2 8.4 (Berkeley) 2/26/94
.\"
-.Dd $Mdocdate: February 5 2015 $
+.Dd $Mdocdate: September 30 2016 $
.Dt READ 2
.Os
.Sh NAME
@@ -152,13 +152,15 @@ is not a valid file or socket descriptor open for reading.
Part of
.Fa buf
points outside the process's allocated address space.
-.It Bq Er EIO
-An I/O error occurred while reading from the file system.
.It Bq Er EINTR
A read from a slow device
(i.e. one that might block for an arbitrary amount of time)
was interrupted by the delivery of a signal
before any data arrived.
+.It Bq Er EIO
+An I/O error occurred while reading from the file system.
+.It Bq Er EISDIR
+The underlying file is a directory.
.El
.Pp
In addition,
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);