Date: Sun, 19 Aug 2001 05:08:38 +0400 From: "Andrey A. Chernov" <ache@nagual.pp.ru> To: Bruce Evans <bde@zeta.org.au> Cc: arch@FreeBSD.ORG, current@FreeBSD.ORG Subject: Re: CFR: lseek() POSIXed patch Message-ID: <20010819050838.A86450@nagual.pp.ru> In-Reply-To: <20010815190108.J19482-100000@besplex.bde.org> References: <20010815125248.A2588@nagual.pp.ru> <20010815190108.J19482-100000@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Updated variant: --- vfs_syscalls.c.old Sat Aug 11 02:14:18 2001 +++ vfs_syscalls.c Sun Aug 19 05:01:32 2001 @@ -1614,29 +1614,44 @@ register struct filedesc *fdp = p->p_fd; register struct file *fp; struct vattr vattr; - int error; + struct vnode *vp; + off_t offset; + int error, noneg; if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) return (EBADF); if (fp->f_type != DTYPE_VNODE) return (ESPIPE); + vp = (struct vnode *)fp->f_data; + noneg = (vp->v_type != VCHR); + offset = SCARG(uap, offset); switch (SCARG(uap, whence)) { case L_INCR: - fp->f_offset += SCARG(uap, offset); + if (noneg && + ((offset > 0 && fp->f_offset > OFF_MAX - offset) || + (offset < 0 && fp->f_offset < OFF_MIN - offset))) + return (EOVERFLOW); + offset += fp->f_offset; break; case L_XTND: - error=VOP_GETATTR((struct vnode *)fp->f_data, &vattr, cred, p); + error = VOP_GETATTR(vp, &vattr, cred, p); if (error) return (error); - fp->f_offset = SCARG(uap, offset) + vattr.va_size; + if (noneg && + ((offset > 0 && vattr.va_size > OFF_MAX - offset) || + (offset < 0 && vattr.va_size < OFF_MIN - offset))) + return (EOVERFLOW); + offset += vattr.va_size; break; case L_SET: - fp->f_offset = SCARG(uap, offset); break; default: return (EINVAL); } + if (noneg && offset < 0) + return (EINVAL); + fp->f_offset = offset; *(off_t *)(p->p_retval) = fp->f_offset; return (0); } -- Andrey A. Chernov http://ache.pp.ru/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010819050838.A86450>