On Wed, Jul 03, 2002 at 01:15:39AM +0800, Connie Chan wrote:
> For pure perl Code, you may try :
> if (-e "filename") { print "existed" }
> else { open (FH, ">filename"); ...... ; close (FH)}

This is a bad idea, as you've introduced a race condition.  What happens if
I symlink 'filename' to some important file in between the time you check if
it exists and open it?


> For temp files, you may try using time, plus
> users IP, that would near 0% that you will 
> have the risk to write to an existed file...

This works if you're the only one dealing with the file, but once you
introduce other, possibly malicious, users into the mix you have to worry
about security.  It may be that he's dealing with the file in this manner,
but he doesn't specify in his question, and it's better to be safe than
exploited.

See my response to the original poster for better ways of opening files
safely, and creating temporary files.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to