Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 May 1998 00:00:05 -0700 (PDT)
From:      Poul-Henning Kamp <phk@critter.freebsd.dk>
To:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: kern/6184 
Message-ID:  <199805200700.AAA10494@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/6184; it has been noted by GNATS.

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: freebsd-gnats-submit@freebsd.org
Cc:  Subject: Re: kern/6184 
Date: Wed, 20 May 1998 08:59:08 +0200

 In message <xzp7m4ob1a5.fsf@hrotti.ifi.uio.no>, Dag-Erling Coidan =?iso-8859-1?
 Q?Sm=F8rgrav?= writes:
 >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
 >
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 "ttyv0" -- What UNIX calls a $20K state-of-the-art, 3D, hi-res color terminal

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199805200700.AAA10494>