From owner-freebsd-bugs Tue Mar 31 07:50:15 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA06739 for freebsd-bugs-outgoing; Tue, 31 Mar 1998 07:50:15 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: (from gnats@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA06673; Tue, 31 Mar 1998 07:50:05 -0800 (PST) (envelope-from gnats) Received: from penguin.wise.edt.ericsson.se (penguin-ext.wise.edt.ericsson.se [194.237.142.5]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA05190 for ; Tue, 31 Mar 1998 07:40:21 -0800 (PST) (envelope-from kent@erix.ericsson.se) Received: from super.du.etx.ericsson.se (root@super.du.etx.ericsson.se [150.236.14.16]) by penguin.wise.edt.ericsson.se (8.7.5/8.7.3/glacier-1.12) with ESMTP id RAA06572 for ; Tue, 31 Mar 1998 17:40:18 +0200 (MET DST) Received: from scotch.du.etx.ericsson.se (kent@scotch.du.etx.ericsson.se [150.236.14.76]) by super.du.etx.ericsson.se (8.9.0.Beta3/8.9.0.Beta3/erix-1.4) with ESMTP id RAA10092 for ; Tue, 31 Mar 1998 17:40:17 +0200 (MET DST) Received: by scotch.du.etx.ericsson.se (8.8.8/client-1.4) id RAA18108; Tue, 31 Mar 1998 17:40:17 +0200 (CEST) Message-Id: <199803311540.RAA18108@scotch.du.etx.ericsson.se> Date: Tue, 31 Mar 1998 17:40:17 +0200 (CEST) From: Kent Boortz Reply-To: kent@erix.ericsson.se To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: kern/6184: No error if resulting file pos in lseek is negative Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 6184 >Category: kern >Synopsis: No error if resulting file pos in lseek is negative >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Mar 31 07:50:02 PST 1998 >Last-Modified: >Originator: >Organization: Ericsson Software Technology >Release: FreeBSD 2.2.5-STABLE i386 >Environment: >Description: In FreeBSD 2.2.5 lseek moves the file position without any error checks. If the resulting position is negative we have the problem that the result value -1 can mean two things, that there was an error or that the file position was set to -1 and no error. We have to clear errno before the call and examine errno after the call to find out if there was an error or not. If the resulting position is negative, Linux and Solaris will preserve the file position before the call to lseek and return an error. Is this a bug in FreeBSD or a different interpretations of the POSIX standard? >How-To-Repeat: #include #include #include #include void main() { char *Name = "myfile"; int pos, fd = open(Name,O_WRONLY | O_CREAT); write(fd,"ABCDEFGH",8); close(fd); fd = open(Name,O_RDONLY); if ((pos = lseek(fd,-5,SEEK_CUR)) != -1) { printf("No error moving to pos -5: %d\n",pos); exit(1); } printf("ERROR: %s\n",strerror(errno)); pos = lseek(fd,0,SEEK_CUR); printf("The error moved the file pointer to: %d\n",pos); } >Fix: I belive the fix should be in the file "/usr/src/sys/kern/vfs_syscalls.c" and the function lseek(). Prior to setting the new file position the function should test if the new value is negative. If so the old position should be preserved and the function return an error with errno EINVAL. >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message