Module Name:    src
Committed By:   njoly
Date:           Sat Jun 14 11:37:35 UTC 2014

Modified Files:
        src/lib/libc/sys: truncate.2
        src/sys/kern: vfs_syscalls.c

Log Message:
Follow OpenGroup online documents for truncate[1] and ftruncate[2].
Fail with EINVAL for length argument negative values.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html
[2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libc/sys/truncate.2
cvs rdiff -u -r1.483 -r1.484 src/sys/kern/vfs_syscalls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/sys/truncate.2
diff -u src/lib/libc/sys/truncate.2:1.26 src/lib/libc/sys/truncate.2:1.27
--- src/lib/libc/sys/truncate.2:1.26	Mon May 31 12:16:20 2010
+++ src/lib/libc/sys/truncate.2	Sat Jun 14 11:37:35 2014
@@ -1,4 +1,4 @@
-.\"	$NetBSD: truncate.2,v 1.26 2010/05/31 12:16:20 njoly Exp $
+.\"	$NetBSD: truncate.2,v 1.27 2014/06/14 11:37:35 njoly Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)truncate.2	8.1 (Berkeley) 6/4/93
 .\"
-.Dd March 16, 2008
+.Dd June 14, 2014
 .Dt TRUNCATE 2
 .Os
 .Sh NAME
@@ -76,6 +76,10 @@ and
 .Fn ftruncate
 are:
 .Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Fa length
+argument was less than 0.
 .It Bq Er EISDIR
 The named file is a directory.
 .It Bq Er EROFS

Index: src/sys/kern/vfs_syscalls.c
diff -u src/sys/kern/vfs_syscalls.c:1.483 src/sys/kern/vfs_syscalls.c:1.484
--- src/sys/kern/vfs_syscalls.c:1.483	Thu Jun 12 21:39:45 2014
+++ src/sys/kern/vfs_syscalls.c	Sat Jun 14 11:37:35 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls.c,v 1.483 2014/06/12 21:39:45 joerg Exp $	*/
+/*	$NetBSD: vfs_syscalls.c,v 1.484 2014/06/14 11:37:35 njoly Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.483 2014/06/12 21:39:45 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.484 2014/06/14 11:37:35 njoly Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -3923,6 +3923,9 @@ sys_truncate(struct lwp *l, const struct
 	struct vattr vattr;
 	int error;
 
+	if (SCARG(uap, length) < 0)
+		return EINVAL;
+
 	error = namei_simple_user(SCARG(uap, path),
 				NSM_FOLLOW_TRYEMULROOT, &vp);
 	if (error != 0)
@@ -3957,6 +3960,9 @@ sys_ftruncate(struct lwp *l, const struc
 	file_t *fp;
 	int error;
 
+	if (SCARG(uap, length) < 0)
+		return EINVAL;
+
 	/* fd_getvnode() will use the descriptor for us */
 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
 		return (error);

Reply via email to