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

Group
 
 

bug #25904: NSData writeToFile ignores existing protected file

Submitter:  Tim Käck <tkack>
Submitted:  Tue 17 Mar 2009 11:24:32 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 18 Mar 2009 05:25:50 AM UTC, comment #1: 
Richard Frith-Macdonald <CaS>
Group 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>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

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
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by tkack (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-03-18 CaS StatusNone Invalid
        Open/ClosedOpen Closed
    2009-03-17 tkack Attached File- Added GNUmakefile, #17722
        Attached File- Added issue.m, #17723

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code