From 2359510ddb135dcc6e80153f51cff0a97b20b597 Mon Sep 17 00:00:00 2001 From: Solar Designer Date: Mon, 26 Jan 2004 04:22:18 +0300 Subject: Re: [perl #15063] /tmp issues Message-ID: <20040125222218.GA13499@openwall.com> Remove insecure usage of /tmp from code and documentation p4raw-id: //depot/perl@22258 --- pod/perlfaq5.pod | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pod/perlfaq5.pod') diff --git a/pod/perlfaq5.pod b/pod/perlfaq5.pod index be10390120..49a348a81c 100644 --- a/pod/perlfaq5.pod +++ b/pod/perlfaq5.pod @@ -141,6 +141,7 @@ temporary files in one process, use a counter: my $count = 0; until (defined(fileno(FH)) || $count++ > 100) { $base_name =~ s/-(\d+)$/"-" . (1 + $1)/e; + # O_EXCL is required for security reasons. sysopen(FH, $base_name, O_WRONLY|O_EXCL|O_CREAT); } if (defined(fileno(FH)) @@ -427,8 +428,8 @@ To open file for update, file must not exist: To open a file without blocking, creating if necessary: - sysopen(FH, "/tmp/somefile", O_WRONLY|O_NDELAY|O_CREAT) - or die "can't open /tmp/somefile: $!": + sysopen(FH, "/foo/somefile", O_WRONLY|O_NDELAY|O_CREAT) + or die "can't open /foo/somefile: $!": Be warned that neither creation nor deletion of files is guaranteed to be an atomic operation over NFS. That is, two processes might both @@ -924,7 +925,7 @@ There's also a File::Tail module from CPAN. If you check L, you'll see that several of the ways to call open() should do the trick. For example: - open(LOG, ">>/tmp/logfile"); + open(LOG, ">>/foo/logfile"); open(STDERR, ">&LOG"); Or even with a literal numeric descriptor: -- cgit v1.2.1