mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-23 18:25:19 +00:00
Disallow truncating to negative file sizes. Doing so causes ffs_truncate()
and perhaps other fs truncate's to go crazy and panic the machine or worse. This fixes the truncate bug reported by Michael Class.
This commit is contained in:
parent
b36a2ba1ce
commit
8fceb1ba2d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=2459
|
@ -36,7 +36,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
|
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
|
||||||
* $Id: vfs_syscalls.c,v 1.4 1994/08/20 16:03:14 davidg Exp $
|
* $Id: vfs_syscalls.c,v 1.5 1994/09/02 04:14:44 davidg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -1613,6 +1613,8 @@ truncate(p, uap, retval)
|
||||||
int error;
|
int error;
|
||||||
struct nameidata nd;
|
struct nameidata nd;
|
||||||
|
|
||||||
|
if (uap->length < 0)
|
||||||
|
return(EINVAL);
|
||||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
|
||||||
if (error = namei(&nd))
|
if (error = namei(&nd))
|
||||||
return (error);
|
return (error);
|
||||||
|
@ -1651,6 +1653,8 @@ ftruncate(p, uap, retval)
|
||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
if (uap->length < 0)
|
||||||
|
return(EINVAL);
|
||||||
if (error = getvnode(p->p_fd, uap->fd, &fp))
|
if (error = getvnode(p->p_fd, uap->fd, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
if ((fp->f_flag & FWRITE) == 0)
|
if ((fp->f_flag & FWRITE) == 0)
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
|
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
|
||||||
* $Id: vfs_syscalls.c,v 1.4 1994/08/20 16:03:14 davidg Exp $
|
* $Id: vfs_syscalls.c,v 1.5 1994/09/02 04:14:44 davidg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -1613,6 +1613,8 @@ truncate(p, uap, retval)
|
||||||
int error;
|
int error;
|
||||||
struct nameidata nd;
|
struct nameidata nd;
|
||||||
|
|
||||||
|
if (uap->length < 0)
|
||||||
|
return(EINVAL);
|
||||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
|
||||||
if (error = namei(&nd))
|
if (error = namei(&nd))
|
||||||
return (error);
|
return (error);
|
||||||
|
@ -1651,6 +1653,8 @@ ftruncate(p, uap, retval)
|
||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
if (uap->length < 0)
|
||||||
|
return(EINVAL);
|
||||||
if (error = getvnode(p->p_fd, uap->fd, &fp))
|
if (error = getvnode(p->p_fd, uap->fd, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
if ((fp->f_flag & FWRITE) == 0)
|
if ((fp->f_flag & FWRITE) == 0)
|
||||||
|
|
Loading…
Reference in a new issue