From: Hugo van der Sanden Date: Fri, 5 Sep 1997 00:00:00 +0000 (+0000) Subject: Trap Time::Local infinite loop X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=160771401404fad17bea1cbac474c73580214f79;p=p5sagit%2Fp5-mst-13.2.git Trap Time::Local infinite loop Here's a new patch for Time::Local that dies if it detects that it is looping: work% perl -wle 'use Time::Local; print timegm(8, 14, 3, 19, 11, 997)' Couldn't handle date (8, 14, 3, 19, 11, 997) at -e line 1 work% Under Linux here, it handles all dates in the years 1970 thru 2038 (70-99, 00-38) and dies for all other years. I don't try to address the fact that strange values are returned for dates in '38 from February onwards: the 31-bit epoch ends at 03:14:07 19th Jan 2038. p5p-msgid: 199710030030.BAA17372@crypt.compulink.co.uk --- diff --git a/lib/Time/Local.pm b/lib/Time/Local.pm index d2d70da..3aa0cfc 100644 --- a/lib/Time/Local.pm +++ b/lib/Time/Local.pm @@ -107,7 +107,9 @@ sub cheat { @g = gmtime($guess); $year += $YearFix if $year < $epoch; $lastguess = ""; + $counter = 0; while ($diff = $year - $g[5]) { + croak "Couldn't handle date (".join(", ",@_).")" if ++$counter > 255; $guess += $diff * (363 * $DAY); @g = gmtime($guess); if (($thisguess = "@g") eq $lastguess){ @@ -116,6 +118,7 @@ sub cheat { $lastguess = $thisguess; } while ($diff = $month - $g[4]) { + croak "Couldn't handle date (".join(", ",@_).")" if ++$counter > 255; $guess += $diff * (27 * $DAY); @g = gmtime($guess); if (($thisguess = "@g") eq $lastguess){