Date: Tue, 31 Mar 1998 17:40:17 +0200 (CEST) From: Kent Boortz <kent@erix.ericsson.se> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: kern/6184: No error if resulting file pos in lseek is negative Message-ID: <199803311540.RAA18108@scotch.du.etx.ericsson.se>
next in thread | raw e-mail | index | archive | help
>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 <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803311540.RAA18108>