From: Nicholas Clark Date: Sat, 28 Feb 2004 16:10:20 +0000 (+0000) Subject: Use File::Temp for tempfiles if it is available. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=003a92ef523fede541513d0991848d9e3d62707a;p=p5sagit%2Fp5-mst-13.2.git Use File::Temp for tempfiles if it is available. (Based on a patch from Solar Designer in Message-ID: <20040125222218.GA13499@openwall.com>, the bulk of which was applied as change 22258) p4raw-id: //depot/perl@22407 --- diff --git a/utils/perlbug.PL b/utils/perlbug.PL index b9906f8..8f3e6a0 100644 --- a/utils/perlbug.PL +++ b/utils/perlbug.PL @@ -89,9 +89,12 @@ BEGIN { $::HaveSend = ($@ eq ""); eval "use Mail::Util;"; $::HaveUtil = ($@ eq ""); + # use secure tempfiles wherever possible + eval "require File::Temp;"; + $::HaveTemp = ($@ eq ""); }; -my $Version = "1.34"; +my $Version = "1.35"; # Changed in 1.06 to skip Mail::Send and Mail::Util if not available. # Changed in 1.07 to see more sendmail execs, and added pipe output. @@ -130,6 +133,7 @@ my $Version = "1.34"; # Changed in 1.32 Use File::Spec->tmpdir TJENNESS 20-08-2000 # Changed in 1.33 Don't require -t STDOUT for -ok. # Changed in 1.34 Added Message-Id RFOLEY 18-06-2002 +# Changed in 1.35 Use File::Temp (patch from Solar Designer) NWCLARK 28-02-2004 # TODO: - Allow the user to re-name the file on mail failure, and # make sure failure (transmission-wise) of Mail::Send is @@ -958,10 +962,18 @@ EOF } sub filename { - my $dir = File::Spec->tmpdir(); - $filename = "bugrep0$$"; - $filename++ while -e File::Spec->catfile($dir, $filename); - $filename = File::Spec->catfile($dir, $filename); + if ($::HaveTemp) { + # Good. Use a secure temp file + my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1); + close($fh); + return $filename; + } else { + # Bah. Fall back to doing things less securely. + my $dir = File::Spec->tmpdir(); + $filename = "bugrep0$$"; + $filename++ while -e File::Spec->catfile($dir, $filename); + $filename = File::Spec->catfile($dir, $filename); + } } sub paraprint {