Bug 125427 - Taint error in duplicates.cgi with perl < 5.6

r=gerv, myk
parent f44a3d6f
...@@ -69,20 +69,36 @@ $sortby = "count" if $sortby eq "dup_count"; ...@@ -69,20 +69,36 @@ $sortby = "count" if $sortby eq "dup_count";
my $today = days_ago(0); my $today = days_ago(0);
my $yesterday = days_ago(1); my $yesterday = days_ago(1);
if (<data/duplicates/dupes$today*>) { # We don't know the exact file name, because the extention depends on the
dbmopen(%dbmcount, "data/duplicates/dupes$today", 0644) # underlying dbm library, which could be anything. We can't glob, because
|| DisplayError("Can't open today ($today)'s dupes file: $!") # perl < 5.6 considers if (<*>) { ... } to be tainted
&& exit; # Instead, just check the return value for today's data and yesterday's,
} # and ignore file not found errors
elsif (<data/duplicates/dupes$yesterday*>) {
dbmopen(%dbmcount, "data/duplicates/dupes$yesterday", 0644) use Errno;
|| DisplayError("Can't open yesterday ($yesterday)'s dupes file: $!") use Fcntl;
&& exit;
} if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$today",
else { O_RDONLY, 0644)) {
DisplayError("There are no duplicate statistics for today ($today) or if ($!{ENOENT}) {
yesterday."); if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$yesterday",
exit; O_RDONLY, 0644)) {
if ($!{ENOENT}) {
ThrowUserError("There are no duplicate statistics for today " .
"($today) or yesterday.",
"Cannot find duplicate statistics");
} else {
ThrowUserError("There are no duplicate statistics for today " .
"($today), and an error occurred when " .
"accessing yesterday's dupes file: $!.",
"Error reading yesterday's dupes file");
}
}
} else {
ThrowUserError("An error occurred when accessing today ($today)'s " .
"dupes file: $!.",
"Error reading today's dupes file");
}
} }
# Copy hash (so we don't mess up the on-disk file when we remove entries) # Copy hash (so we don't mess up the on-disk file when we remove entries)
...@@ -101,11 +117,15 @@ my $dobefore = 0; ...@@ -101,11 +117,15 @@ my $dobefore = 0;
my %delta; my %delta;
my $whenever = days_ago($changedsince); my $whenever = days_ago($changedsince);
if (<data/duplicates/dupes$whenever*>) { if (!tie(%before, 'AnyDBM_File', "data/duplicates/dupes$whenever",
dbmopen(%before, "data/duplicates/dupes$whenever", 0644) O_RDONLY, 0644)) {
|| DisplayError("Can't open $changedsince days ago ($whenever)'s " . # Ignore file not found errors
"dupes file: $!"); if (!$!{ENOENT}) {
ThrowUserError("Can't open $changedsince days ago ($whenever)'s " .
"dupes file: $!",
"Error reading previous dupes file");
}
} else {
# Calculate the deltas # Calculate the deltas
($delta{$_} = $count{$_} - $before{$_}) foreach (keys(%count)); ($delta{$_} = $count{$_} - $before{$_}) foreach (keys(%count));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment