Kaynağa Gözat

Dpkg::Changelog::Entry::Debian: Only warn on invalid week days

Regression introduced in commit 7a71b4b78e8a81158c45073dee05b0d1cc46b71c.

The previous implementation using Date::Parse ignored invalid week
days, and the new one using Time::Piece is strict, so we get fatal
errors. Validate the week day ourselves, emit a warning in case of
an invalid value, and ignore it when passing the value to strptime
from Time::Piece.

Reported-by: Jakub Wilk <jwilk@debian.org>
Guillem Jover 11 yıl önce
ebeveyn
işleme
afef8fbf76
2 değiştirilmiş dosya ile 16 ekleme ve 5 silme
  1. 6 0
      debian/changelog
  2. 10 5
      scripts/Dpkg/Changelog/Entry/Debian.pm

+ 6 - 0
debian/changelog

@@ -1,5 +1,11 @@
 dpkg (1.18.3) UNRELEASED; urgency=low
 
+  [ Guillem Jover ]
+  * Perl modules:
+    - Only warn on invalid week days instead of aborting in
+      Dpkg::Changelog::Entry::Debian. Regression introduced in dpkg 1.18.2.
+      Reported by Jakub Wilk <jwilk@debian.org>.
+
   [ Updated programs translations ]
   * Catalan (Jordi Mallach).
 

+ 10 - 5
scripts/Dpkg/Changelog/Entry/Debian.pm

@@ -64,7 +64,9 @@ our $regex_header = qr/^(\w$name_chars*) \(([^\(\) \t]+)\)((?:\s+$name_chars+)+)
 
 # The matched content is the maintainer name ($1), its email ($2),
 # some blanks ($3) and the timestamp ($4).
-our $regex_trailer = qr/^ \-\- (.*) <(.*)>(  ?)((\w+\,\s*)?\d{1,2}\s+\w+\s+\d{4}\s+\d{1,2}:\d\d:\d\d\s+[-+]\d{4})\s*$/o;
+our $regex_trailer = qr/^ \-\- (.*) <(.*)>(  ?)(((\w+)\,\s*)?(\d{1,2}\s+\w+\s+\d{4}\s+\d{1,2}:\d\d:\d\d\s+[-+]\d{4}))\s*$/o;
+
+my %week_day = map { $_ => 1 } qw(Mon Tue Wed Thu Fri Sat Sun);
 
 ## use critic
 
@@ -165,12 +167,15 @@ sub check_trailer {
 	    push @errors, g_('badly formatted trailer line');
 	}
 
-	my $fmt = '';
-	$fmt .= '%a, ' if defined $5;
-	$fmt .= '%d %b %Y %T %z';
+	# Validate the week day. Date::Parse used to ignore it, but Time::Piece
+	# is much more strict and it does not gracefully handle bogus values.
+	if (defined $5 and not exists $week_day{$6}) {
+	    push @errors, sprintf(g_('ignoring invalid week day \'%s\''), $6);
+	}
 
+	# Ignore the week day ('%a, '), as we have validated it above.
 	local $ENV{LC_ALL} = 'C';
-	unless (defined Time::Piece->strptime($4, $fmt)) {
+	unless (defined Time::Piece->strptime($7, '%d %b %Y %T %z')) {
 	    push @errors, sprintf(g_("couldn't parse date %s"), $4);
 	}
     } else {