bugGNUstep - Bugs: bug #25904, NSData writeToFile ignores...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #25904: NSData writeToFile ignores existing protected file

Submitted by:  Tim Käck <tkack>
Submitted on:  Tue 17 Mar 2009 11:24:32 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: Closed

Wed 18 Mar 2009 05:25:50 AM UTC, comment #1:

Not a bug ... this is the expected, documented behavior.

See
http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSData.html#method$NSData-writeToFile$atomically$

and
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/occ/instm/NSData/writeToFile:atomically:

You can also confirm that the behavior on MacOS-X is the same as on GNUstep but running a test program there.

Richard Frith-Macdonald <CaS>
Project Member
Tue 17 Mar 2009 11:24:32 PM UTC, original submission:

It seems that we are using rename() in NSData.m:1054.
GLibc function rename will first delete the oldfile before renaming the newfile to the old name.
If a file is readonly, it can still be overwritten by the writeToFile as long as the containing directory is writable and that the file is owned by the same owner that executes the tool.

I have attached some simple code to demonstrate this.
Here is the steps:

1. Create a file in /tmp/ called permissionstestFile.txt
2, Add some text in the file
3. chmod 000 /tmp/permissionstestFile.txt
4. Compile testFilePerms tool attached.
5. Run it with './obj/testFilePerms'
6. chmod u+rw /tmp/permissionstestFile.txt
7. cat /tmp/permissionstestFile.txt

Note that this behavior is noted in http://www.gnu.org/software/libc/manual/html_node/Renaming-Files.html#Renaming-Files as follows for the rename() function:
"If oldname is not a directory, then any existing file named newname is removed during the renaming operation. However, if newname is the name of a directory, rename fails in this case. "

Perhaps there should have a check before renaming if the file is writeable or not. File attributes are already collected at that point so it shouldn't be much overhead with the test.

Tim Käck <tkack>

 

Attached Files
file #17722:  GNUmakefile added by tkack (437B - application/octet-stream)
file #17723:  issue.m added by tkack (314B - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by CaS (Posted a comment)
  • -unavailable- added by tkack (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 18 Mar 2009 05:25:50 AM UTCCaSStatusNone=>Invalid
      Open/ClosedOpen=>Closed
    Tue 17 Mar 2009 11:24:32 PM UTCtkackAttached File-=>Added GNUmakefile, #17722
      Attached File-=>Added issue.m, #17723

    Back to the top


    Powered by Savane 3.1-cleanup1