summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-11-17 06:00:53 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-11-17 06:00:53 +0000
commit56ddb51a6a65e36924276ea742a9954979bf6054 (patch)
tree423195a4bcf51716dbf260b95f93aa0020b6a1c9
parentcf9c1e76089fd1293806c61cbde28ba306f78d75 (diff)
make chmod() and fchmod() return EINVAL for bad mode bits
-rw-r--r--lib/libc/sys/chmod.23
-rw-r--r--sys/kern/vfs_syscalls.c8
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/libc/sys/chmod.2 b/lib/libc/sys/chmod.2
index e32bd0f6ced..a87b3ac4686 100644
--- a/lib/libc/sys/chmod.2
+++ b/lib/libc/sys/chmod.2
@@ -164,6 +164,9 @@ The descriptor is not valid.
.It Bq Er EINVAL
.Fa Fd
refers to a socket, not to a file.
+.It Bq Er EINVAL
+.Fa mode
+is not valid, ie. contains extra bits.
.It Bq Er EROFS
The file resides on a read-only file system.
.It Bq Er EIO
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 83dc7e79bc3..6aea61f5fa4 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.28 1997/11/06 05:58:29 csapuntz Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.29 1997/11/17 06:00:52 deraadt Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -1529,6 +1529,9 @@ sys_chmod(p, v, retval)
int error;
struct nameidata nd;
+ if (SCARG(uap, mode) & ~ALLPERMS)
+ return (EINVAL);
+
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
if ((error = namei(&nd)) != 0)
return (error);
@@ -1565,6 +1568,9 @@ sys_fchmod(p, v, retval)
struct file *fp;
int error;
+ if (SCARG(uap, mode) & ~ALLPERMS)
+ return (EINVAL);
+
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
vp = (struct vnode *)fp->f_data;