From erdgeist@mail.gate5.de  Fri Apr 11 08:46:30 2003
Return-Path: <erdgeist@mail.gate5.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 22F1537B401
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Apr 2003 08:46:30 -0700 (PDT)
Received: from mail.gate5.de (gatekeeper.gate5.de [212.84.193.254])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A90D643F93
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Apr 2003 08:46:28 -0700 (PDT)
	(envelope-from erdgeist@mail.gate5.de)
Received: from mail.gate5.de (localhost [127.0.0.1])
	by mail.gate5.de (8.12.9/8.12.9) with ESMTP id h3BDU8Cc000710
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Apr 2003 15:30:08 +0200 (CEST)
	(envelope-from erdgeist@mail.gate5.de)
Received: (from erdgeist@localhost)
	by mail.gate5.de (8.12.9/8.12.9/Submit) id h3ANbfWe001002;
	Fri, 11 Apr 2003 01:37:41 +0200 (CEST)
Message-Id: <200304102337.h3ANbfWe001002@mail.gate5.de>
Date: Fri, 11 Apr 2003 01:37:41 +0200 (CEST)
From: Erdgeist <erdgeist@erdgeist.org>
Reply-To: Erdgeist <erdgeist@erdgeist.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: lseek to negative file positions screws up flags
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         50825
>Category:       misc
>Synopsis:       lseek to negative file positions screws up flags
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 11 08:50:16 PDT 2003
>Closed-Date:    Wed Apr 23 07:00:54 PDT 2003
>Last-Modified:  Wed Apr 23 07:00:54 PDT 2003
>Originator:     Erdgeist
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
erdgeist.org
>Environment:
System: FreeBSD bauklotz.gate5.de 5.0-CURRENT FreeBSD 5.0-CURRENT #3: Thu Apr 10 20:53:26 CEST 2003 root@bauklotz.gate5.de:/usr/obj/usr/src/sys/bauklotz i386

>Description:
        Doing a lseek to a position before the file results in corrupted
        File flags.
>How-To-Repeat:
#include <unistd.h>
#include <fcntl.h>

int main( ) {
    int a = open( "testfile", O_CREAT | O_RDWR );
    lseek( a, -10, SEEK_CUR);
    close( a );
    return 0;
}
>Fix:

>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@lcs.mit.edu>
To: Erdgeist <erdgeist@erdgeist.org>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: misc/50825: lseek to negative file positions screws up flags
Date: Fri, 11 Apr 2003 18:34:54 -0400 (EDT)

 <<On Fri, 11 Apr 2003 01:37:41 +0200 (CEST), Erdgeist <erdgeist@erdgeist.org> said:
 
 >         Doing a lseek to a position before the file results in corrupted
 >         File flags.
 
 I am not able to reproduce your problem:
 
   wollman@khavrinen(1485)$ cc -O -Wall foo.c
 wollman@khavrinen(1486)$ ./a.out
 wollman@khavrinen(1487)$ ls -lo testfile
 -rw-r--r--  1 wollman  users  - 0 Apr 11 18:32 testfile
 
 I did fix a bug in your program; your call to open() was missing an
 argument.  However, this should have no impact on the file flags, only
 the mode.
 
 -GAWollman
 

From: David Taylor <davidt@yadt.co.uk>
To: Erdgeist <erdgeist@erdgeist.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: misc/50825: lseek to negative file positions screws up flags
Date: Sat, 12 Apr 2003 02:49:37 +0100

 On Fri, 11 Apr 2003, Erdgeist wrote:
 > >Description:
 >         Doing a lseek to a position before the file results in corrupted
 >         File flags.
 
 Actually, if you remove the lseek(); line from the test program below, the
 file mode will still be screwed up.
 
 > >How-To-Repeat:
 > #include <unistd.h>
 > #include <fcntl.h>
 > 
 > int main( ) {
 >     int a = open( "testfile", O_CREAT | O_RDWR );
                                 ^^^^^^^        ^^^
 The problem is this:
 
      int
      open(const char *path, int flags, ...);
 
      The flags argument may indicate the file is to be cre-ated if it does
      not exist (by specifying the O_CREAT flag).  In this case open()
      requires a third argument mode_t mode, and the file is created
      with mode mode as described in chmod(2) and modified by the process'
      umask value (see umask(2)).
 
 Replacing the above line with:
 
       int a = open( "testfile", O_CREAT | O_RDWR, 0666 );
 
 results in the program working as it should.
 
 >     lseek( a, -10, SEEK_CUR);
 >     close( a );
 >     return 0;
 > }
 
 -- 
 David Taylor
 davidt@yadt.co.uk
 "The future just ain't what it used to be"

From: Dirk Engling <erdgeist@erdgeist.org>
To: David Taylor <davidt@yadt.co.uk>
Cc: <FreeBSD-gnats-submit@FreeBSD.org>
Subject: Re: misc/50825: lseek to negative file positions screws up flags
Date: Sat, 12 Apr 2003 14:53:03 +0200 (CEST)

 On Sat, 12 Apr 2003, David Taylor wrote:
 
 > Replacing the above line with:
 >
 >       int a = open( "testfile", O_CREAT | O_RDWR, 0666 );
 >
 > results in the program working as it should.
 
 How embarassing, thank you. I migrated from fopen() and
 did not notice the additional parameter.
 
 Regards
 
   Dirk
 
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Wed Apr 23 06:58:57 PDT 2003 
State-Changed-Why:  
The submitter agrees it is not a bug. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=50825 
>Unformatted:
