summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/sys/truncate.26
-rw-r--r--sys/kern/vfs_syscalls.c8
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/libc/sys/truncate.2 b/lib/libc/sys/truncate.2
index 7f519cbb63b..ee4f1aeb3e4 100644
--- a/lib/libc/sys/truncate.2
+++ b/lib/libc/sys/truncate.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: truncate.2,v 1.11 2003/06/02 20:18:39 millert Exp $
+.\" $OpenBSD: truncate.2,v 1.12 2004/07/18 12:05:07 avsm Exp $
.\" $NetBSD: truncate.2,v 1.7 1995/02/27 12:39:00 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -114,6 +114,10 @@ references a socket, not a file.
The
.Fa fd
is not open for writing.
+.It Bq Er EINVAL
+The
+.Fa length
+is a negative value.
.El
.Sh SEE ALSO
.Xr open 2
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index a29667e6d35..a753fee661e 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.114 2004/07/13 21:04:29 millert Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.115 2004/07/18 12:05:07 avsm Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -2278,11 +2278,13 @@ sys_ftruncate(p, v, retval)
struct vattr vattr;
struct vnode *vp;
struct file *fp;
+ off_t len;
int error;
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- if ((fp->f_flag & FWRITE) == 0) {
+ len = SCARG(uap, length);
+ if ((fp->f_flag & FWRITE) == 0 || len < 0) {
error = EINVAL;
goto bad;
}
@@ -2293,7 +2295,7 @@ sys_ftruncate(p, v, retval)
error = EISDIR;
else if ((error = vn_writechk(vp)) == 0) {
VATTR_NULL(&vattr);
- vattr.va_size = SCARG(uap, length);
+ vattr.va_size = len;
error = VOP_SETATTR(vp, &vattr, fp->f_cred, p);
}
VOP_UNLOCK(vp, 0, p);