INN commit: branches/2.5/scripts (innreport.in)

INN Commit rra at isc.org
Tue Jun 12 17:59:28 UTC 2012


    Date: Tuesday, June 12, 2012 @ 10:59:28
  Author: iulius
Revision: 9415

innreport:  ignore invalid dates in daily HTML reports

Lines containing invalid dates are now skipped by innreport.  The behaviour
of innreport was changed by the previous commit because the use of
Time::Local::timelocal() validates the date and fails when the date
is invalid.  We now properly skip it.

Thanks to Petr Novopashenniy for the bug report.

Modified:
  branches/2.5/scripts/innreport.in

--------------+
 innreport.in |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Modified: innreport.in
===================================================================
--- innreport.in	2012-06-12 17:58:47 UTC (rev 9414)
+++ innreport.in	2012-06-12 17:59:28 UTC (rev 9415)
@@ -739,6 +739,8 @@
 }
 
 # Convert a date to number of seconds since epoch.
+# Return undef in case the date is invalid.
+#
 # Leap years are handled correctly, daylight saving is not.
 # Usage: $num = &ConvDate ($date, $wrap_around);
 # Date format is "2012 Aug 22 01:49:40".
@@ -767,8 +769,14 @@
   # Take the previous year if a change of year has been detected and
   # the date is after May, 1st.
   $y-- if $wrap > 0 and $m > 4;
+
   # Convert the given date to the number of seconds since epoch.
-  return Time::Local::timelocal($s, $mn, $h, $d, $m, $y);
+  # Use an eval block to catch the error in case of an invalid date.
+  my $epochtime = undef;
+  eval {
+    $epochtime = Time::Local::timelocal($s, $mn, $h, $d, $m, $y);
+  };
+  return $epochtime;
 }
 
 # Compare 2 filenames
@@ -1120,6 +1128,11 @@
         }
 	my $start_sec = &ConvDate ($year . ' ' . $start, 0);
 	my $end_sec = &ConvDate ($year . ' ' . $end, 0);
+        if (!defined($start_sec) or !defined($end_sec))
+        { 
+          warn "Invalid date in DB file ignored: $k" if ($DEBUG);
+          next;
+        }
         if ($start_sec - $end_sec == 0)
         {
           warn "Time range 0 in DB file ignored: $k" if ($DEBUG);



More information about the inn-committers mailing list