diff options
author | justdave%syndicomm.com <> | 2003-04-25 06:17:29 +0200 |
---|---|---|
committer | justdave%syndicomm.com <> | 2003-04-25 06:17:29 +0200 |
commit | 901c2d3a8ad01b13111145ec63234f3bd6f02871 (patch) | |
tree | cfdf672df926572faac9cfe570767fce56c8e65c /showdependencygraph.cgi | |
parent | e9841817aa2bb7aef16e6499a9db2d5254a31c5f (diff) | |
download | bugzilla-901c2d3a8ad01b13111145ec63234f3bd6f02871.tar.gz bugzilla-901c2d3a8ad01b13111145ec63234f3bd6f02871.tar.xz |
Bug 197153: Fix for insecure temporary filename handling.
Patch by Brad Baetz <bbaetz@acm.org>
r= justdave, gerv
a= justdave
Diffstat (limited to 'showdependencygraph.cgi')
-rwxr-xr-x | showdependencygraph.cgi | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/showdependencygraph.cgi b/showdependencygraph.cgi index 37b7c74cc..61278b5f3 100755 --- a/showdependencygraph.cgi +++ b/showdependencygraph.cgi @@ -25,6 +25,8 @@ use strict; use lib qw(.); +use File::Temp; + require "CGI.pl"; ConnectToDatabase(); @@ -62,11 +64,11 @@ sub CreateImagemap { } sub AddLink { - my ($blocked, $dependson) = (@_); + my ($blocked, $dependson, $fh) = (@_); my $key = "$blocked,$dependson"; if (!exists $edgesdone{$key}) { $edgesdone{$key} = 1; - print DOT "$blocked -> $dependson\n"; + print $fh "$blocked -> $dependson\n"; $seen{$blocked} = 1; $seen{$dependson} = 1; } @@ -78,12 +80,13 @@ if (!defined($::FORM{'id'}) && !defined($::FORM{'doall'})) { ThrowCodeError("missing_bug_id"); } -my $filename = "data/webdot/$$.dot"; +my ($fh, $filename) = File::Temp::tempfile("XXXXXXXXXX", + SUFFIX => '.dot', + DIR => "data/webdot"); my $urlbase = Param('urlbase'); -open(DOT, ">$filename") || die "Can't create $filename"; -print DOT "digraph G {"; -print DOT qq{ +print $fh "digraph G {"; +print $fh qq{ graph [URL="${urlbase}query.cgi", rankdir=$::FORM{'rankdir'}, size="64,64"] node [URL="${urlbase}show_bug.cgi?id=\\N", style=filled, color=lightgrey] }; @@ -95,7 +98,7 @@ if ($::FORM{'doall'}) { while (MoreSQLData()) { my ($blocked, $dependson) = FetchSQLData(); - AddLink($blocked, $dependson); + AddLink($blocked, $dependson, $fh); } } else { foreach my $i (split('[\s,]+', $::FORM{'id'})) { @@ -119,7 +122,7 @@ if ($::FORM{'doall'}) { push @stack, $dependson; } - AddLink($blocked, $dependson); + AddLink($blocked, $dependson, $fh); } } @@ -159,15 +162,15 @@ foreach my $k (keys(%seen)) { } if (@params) { - print DOT "$k [" . join(',', @params) . "]\n"; + print $fh "$k [" . join(',', @params) . "]\n"; } else { - print DOT "$k\n"; + print $fh "$k\n"; } } -print DOT "}\n"; -close DOT; +print $fh "}\n"; +close $fh; chmod 0777, $filename; @@ -180,11 +183,23 @@ if ($webdotbase =~ /^https?:/) { $vars->{'map_url'} = $url . ".map"; } else { # Local dot installation - my $pngfilename = "data/webdot/$$.png"; - my $mapfilename = "data/webdot/$$.map"; - system("$webdotbase","-Tpng","-o","$pngfilename","$filename"); + my $dotfh; + my ($pngfh, $pngfilename) = File::Temp::tempfile("XXXXXXXXXX", + SUFFIX => '.png', + DIR => 'data/webdot'); + open (DOT, '-|') or exec ($webdotbase, "-Tpng", $filename); + print $pngfh $_ while <DOT>; + close DOT; + close $pngfh; $vars->{'image_url'} = $pngfilename; - system("$webdotbase","-Tismap","-o","$mapfilename","$filename"); + + my ($mapfh, $mapfilename) = File::Temp::tempfile("XXXXXXXXXX", + SUFFIX => '.map', + DIR => 'data/webdot'); + open (DOT, '-|') or exec ($webdotbase, "-Tismap", $filename); + print $mapfh $_ while <DOT>; + close DOT; + close $mapfh; $vars->{'image_map'} = CreateImagemap($mapfilename); } |