From owner-freebsd-hackers Tue Aug 24 13:28:21 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from lamb.sas.com (lamb.sas.com [192.35.83.8]) by hub.freebsd.org (Postfix) with ESMTP id 5B42715125 for ; Tue, 24 Aug 1999 13:28:13 -0700 (PDT) (envelope-from jwd@unx.sas.com) Received: from mozart (mozart.unx.sas.com [192.58.184.8]) by lamb.sas.com (8.9.3/8.9.1) with SMTP id QAA01061 for ; Tue, 24 Aug 1999 16:25:57 -0400 (EDT) Received: from bb01f39.unx.sas.com by mozart (5.65c/SAS/Domains/5-6-90) id AA21513; Tue, 24 Aug 1999 16:25:26 -0400 Received: (from jwd@localhost) by bb01f39.unx.sas.com (8.9.1/8.9.1) id QAA24724 for freebsd-hackers@freebsd.org; Tue, 24 Aug 1999 16:25:26 -0400 (EDT) (envelope-from jwd) From: "John W. DeBoskey" Message-Id: <199908242025.QAA24724@bb01f39.unx.sas.com> Subject: seek to negative offset? To: freebsd-hackers@freebsd.org Date: Tue, 24 Aug 1999 16:25:26 -0400 (EDT) X-Mailer: ELM [version 2.4ME+ PL43 (25)] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, The subject says it all... We have some code that scans files backwards... On the systems we've been running this program on, the lseek man page typically lists: [EINVAL] The resulting file offset would be negative. The following program run under freebsd-current shows the problem: #include #include #include #include main() { int offset, myerrno; int myfd; myfd = open("/etc/passwd", O_RDONLY); printf("Seeking to byte 512...\n"); offset = lseek(myfd, 512, SEEK_SET); myerrno = errno; printf("offset after first lseek: %d\nerrno=%d\n\n",offset,myerrno); printf("Seeking relative -1024 bytes...\n"); offset = lseek(myfd, -1024, SEEK_CUR); myerrno = errno; printf("offset after second lseek: %d\nerrno=%d\n\n",offset,myerrno); printf("Current offset location: %d\n",lseek(myfd, 0, SEEK_CUR)); close(myfd); } sample output: Seeking to byte 512... offset after first lseek: 512 errno=0 Seeking relative -1024 bytes... offset after second lseek: -512 errno=0 Current offset location: -512 In looking through /usr/src/sys/kern/vfs_syscalls.c I can't see where we do any validation on the resulting seek location... Do the appropriate folks think this is a bug? How about posix? Should I go ahead and submit a pr with a patch? Thanks! John To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message