Date: 17 Apr 1998 23:12:34 +0200 From: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ) To: current@FreeBSD.ORG Subject: kern/6184 Message-ID: <xzp7m4ob1a5.fsf@hrotti.ifi.uio.no>
next in thread | raw e-mail | index | archive | help
I have a patch which I hope fixes kern/6184 (lseek allows seeks to
negative offsets), but I don't want to commit it without having
someone look at it first:
Index: src/sys/kern/vfs_syscalls.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_syscalls.c,v
retrieving revision 1.97
diff -u -r1.97 vfs_syscalls.c
--- vfs_syscalls.c 1998/04/08 18:31:57 1.97
+++ vfs_syscalls.c 1998/04/17 21:03:13
@@ -1324,6 +1324,7 @@
register struct filedesc *fdp = p->p_fd;
register struct file *fp;
struct vattr vattr;
+ off_t ofs;
int error;
if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
@@ -1333,21 +1334,22 @@
return (ESPIPE);
switch (SCARG(uap, whence)) {
case L_INCR:
- fp->f_offset += SCARG(uap, offset);
+ ofs = fp->f_offset + SCARG(uap, offset);
break;
case L_XTND:
error=VOP_GETATTR((struct vnode *)fp->f_data, &vattr, cred, p);
if (error)
return (error);
- fp->f_offset = SCARG(uap, offset) + vattr.va_size;
+ ofs = SCARG(uap, offset) + vattr.va_size;
break;
case L_SET:
- fp->f_offset = SCARG(uap, offset);
+ ofs = SCARG(uap, offset);
break;
default:
return (EINVAL);
}
- *(off_t *)(p->p_retval) = fp->f_offset;
+ if (ofs < 0) return (EINVAL);
+ *(off_t *)(p->p_retval) = fp->f_offset = ofs;
return (0);
}
Index: src/lib/libc/sys/lseek.2
===================================================================
RCS file: /home/ncvs/src/lib/libc/sys/lseek.2,v
retrieving revision 1.6
diff -u -r1.6 lseek.2
--- lseek.2 1997/02/22 15:04:01 1.6
+++ lseek.2 1998/04/17 21:05:23
@@ -120,7 +120,7 @@
is associated with a pipe, socket, or FIFO.
.It Bq Er EINVAL
.Fa Whence
-is not a proper value.
+is not a proper value, or the resulting offset is negative.
.El
.Sh SEE ALSO
.Xr dup 2 ,
--
Nobody else has a .sig like this one.
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?xzp7m4ob1a5.fsf>
