Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^5: opening files: link checking and race conditions

by Eimi Metamorphoumai (Deacon)
on Aug 03, 2005 at 17:57 UTC ( #480584=note: print w/replies, xml ) Need Help??

in reply to Re^4: opening files: link checking and race conditions
in thread opening files: link checking and race conditions

# we have checked for both existence and "type == symlink" on the same + stat call, # so either it's a link, or it's non-existent, or it's safe to write o +utput
Or you opened the symlink, someone replaced it with a regular file, and you statted that. Again, you can make it pretty hard to exploit, but you can't get rid of it entirely without either doing it atomically at the time of the open (O_NOFOLLOW) or can check on the filehandle you actually have open (and not what that name points to now).

What might work (but I'm not at all certain) would be to stat the filehandle you have open, stat the file you thought you opened, and confirm that they have the same inode and that it isn't a symlink.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480584]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2020-10-29 03:11 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (268 votes). Check out past polls.