Просмотр исходного кода

Dpkg::Changelog::Entry::Debian: Catch bogus month names

Check if the month is a valid abbreviated month name, with proper
capitalization, and check explicitly for unabbreviated month names,
otherwise the error message might be too confusing.
Guillem Jover лет назад: 11
Родитель
Сommit
21f5898d84
2 измененных файлов с 21 добавлено и 2 удалено
  1. 2 0
      debian/changelog
  2. 19 2
      scripts/Dpkg/Changelog/Entry/Debian.pm

+ 2 - 0
debian/changelog

@@ -21,6 +21,8 @@ dpkg (1.18.3) UNRELEASED; urgency=low
     - Do not abort on parse errors from Time::Piece->strptime() for the
     - Do not abort on parse errors from Time::Piece->strptime() for the
       changelog trailer date, just queue them so that the caller can decide
       changelog trailer date, just queue them so that the caller can decide
       if they should be warnings or actual errors. Closes: #795936
       if they should be warnings or actual errors. Closes: #795936
+    - Validate the changelog trailer date, and catch and warn or error on
+      bogus month names, such as unknown or unabbreviated ones.
   * Test suite:
   * Test suite:
     - Get the reference build flags from dpkg-buildflags.pl, instead of
     - Get the reference build flags from dpkg-buildflags.pl, instead of
       hardcoding them, which might not match depending on the architecture.
       hardcoding them, which might not match depending on the architecture.

+ 19 - 2
scripts/Dpkg/Changelog/Entry/Debian.pm

@@ -63,10 +63,18 @@ my $name_chars = qr/[-+0-9a-z.]/i;
 our $regex_header = qr/^(\w$name_chars*) \(([^\(\) \t]+)\)((?:\s+$name_chars+)+)\;(.*?)\s*$/i;
 our $regex_header = qr/^(\w$name_chars*) \(([^\(\) \t]+)\)((?:\s+$name_chars+)+)\;(.*?)\s*$/i;
 
 
 # The matched content is the maintainer name ($1), its email ($2),
 # 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;
+# some blanks ($3) and the timestamp ($4), which is decomposed into
+# day of week ($6), date-time ($7) and this into month name ($8).
+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);
 my %week_day = map { $_ => 1 } qw(Mon Tue Wed Thu Fri Sat Sun);
+my %month_abbrev = map { $_ => 1 } qw(
+    Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
+);
+my %month_name = map { $_ => } qw(
+    January February March April May June July
+    August September October November December
+);
 
 
 ## use critic
 ## use critic
 
 
@@ -178,6 +186,15 @@ sub check_trailer {
 	eval {
 	eval {
 	    Time::Piece->strptime($7, '%d %b %Y %T %z');
 	    Time::Piece->strptime($7, '%d %b %Y %T %z');
 	} or do {
 	} or do {
+	    # Validate the month. Date::Parse used to accept both abbreviated
+	    # and full months, but Time::Piece strptime() implementation only
+	    # matches the abbreviated one with %b, which is what we want anyway.
+	    if (exists $month_name{$8}) {
+	        push @errors, sprintf(g_('uses full instead of abbreviated month name \'%s\''),
+	                              $8, $month_name{$8});
+	    } elsif (not exists $month_abbrev{$8}) {
+	        push @errors, sprintf(g_('invalid abbreviated month name \'%s\''), $8);
+	    }
 	    push @errors, sprintf(g_("cannot parse non-comformant date '%s'"), $7);
 	    push @errors, sprintf(g_("cannot parse non-comformant date '%s'"), $7);
 	};
 	};
     } else {
     } else {