From 57c2bb80e2f94dfcbf08532f72c7ed568ceef7be Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 1 Jan 2020 03:28:22 +0000 Subject: nntp: handle 2-digit year "70" properly Time::Local has the concept of a "rolling century" which is defined at 50 years on either side of the current year. Since it's now 2020 and >50 years since the Unix epoch, the year "70" gets interpreted by Time::Local as 2070-01-01 instead of 1970-01-01. Since NNTP servers are unlikely to store messages from the future, we'll feed 4-digit year to Time::Local::{timegm,timelocal} and hopefully not have to worry about things until Y10K. This fixes test failures on t/v2writable.t and t/nntpd.t since 2020-01-01. --- lib/PublicInbox/NNTP.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 6845e872..95c9082d 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -220,16 +220,17 @@ sub parse_time ($$;$) { $gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt"; $gmt = 1; } - my @now = $gmt ? gmtime : localtime; my ($YYYY, $MM, $DD); if (bytes::length($date) == 8) { # RFC 3977 allows YYYYMMDD ($YYYY, $MM, $DD) = unpack('A4A2A2', $date); } else { # legacy clients send YYMMDD - ($YYYY, $MM, $DD) = unpack('A2A2A2', $date); + my $YY; + ($YY, $MM, $DD) = unpack('A2A2A2', $date); + my @now = $gmt ? gmtime : localtime; my $cur_year = $now[5] + 1900; - if ($YYYY > $cur_year) { - $YYYY += int($cur_year / 1000) * 1000 - 100; - } + my $cur_cent = int($cur_year / 100) * 100; + $YYYY = (($YY + $cur_cent) > $cur_year) ? + ($YY + 1900) : ($YY + $cur_cent); } if ($gmt) { timegm($ss, $mm, $hh, $DD, $MM - 1, $YYYY); -- cgit v1.2.3-24-ge0c7