summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2009-09-02 19:05:45 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2009-09-02 19:05:45 +0000
commit627063c738643dbf693d1297289ba037acb9c373 (patch)
treefcce480b7e97d7e133fcefa2584b0994307d1740
parent17a472fb8f7ec24b10b391b1db7dc7d2998bdec8 (diff)
check if we have access to the vnode before checking if we can write to
it. thib@ ok'd the idea and an earlier diff.
-rw-r--r--sys/kern/vfs_syscalls.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 1bc41d8f86c..554a3ae3353 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.156 2009/07/09 22:29:56 thib Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.157 2009/09/02 19:05:44 fgsch Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -1018,8 +1018,8 @@ sys_fhopen(struct proc *p, void *v, register_t *retval)
error = EISDIR;
goto bad;
}
- if ((error = vn_writechk(vp)) != 0 ||
- (error = VOP_ACCESS(vp, VWRITE, cred, p)) != 0)
+ if ((error = VOP_ACCESS(vp, VWRITE, cred, p)) != 0 ||
+ (error = vn_writechk(vp)) != 0)
goto bad;
}
if (flags & O_TRUNC) {
@@ -1480,8 +1480,10 @@ sys_access(struct proc *p, void *v, register_t *retval)
flags |= VWRITE;
if (SCARG(uap, flags) & X_OK)
flags |= VEXEC;
- if ((flags & VWRITE) == 0 || (error = vn_writechk(vp)) == 0)
- error = VOP_ACCESS(vp, flags, cred, p);
+
+ error = VOP_ACCESS(vp, flags, cred, p);
+ if (!error && (flags & VWRITE))
+ error = vn_writechk(vp);
}
vput(vp);
out1:
@@ -2041,8 +2043,8 @@ sys_truncate(struct proc *p, void *v, register_t *retval)
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
if (vp->v_type == VDIR)
error = EISDIR;
- else if ((error = vn_writechk(vp)) == 0 &&
- (error = VOP_ACCESS(vp, VWRITE, p->p_ucred, p)) == 0) {
+ else if ((error = VOP_ACCESS(vp, VWRITE, p->p_ucred, p)) == 0 &&
+ (error = vn_writechk(vp)) == 0) {
VATTR_NULL(&vattr);
vattr.va_size = SCARG(uap, length);
error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);