Browse Source

Dpkg::Changelog: Cope gracefully with a missing trailer timestamp

The get_timepiece methods might return an undef value if there was no
timestamp in the trailer. Do not call the Time::Piece epoch method in
that case, as that causes a perl error.

Regression introduced in commit ea22158eb8b0dcaf42b0cdacd5b4560764f353c8.

Closes: #843248
Based-on-patch-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Guillem Jover 7 years ago
parent
commit
b8227f0b53

+ 3 - 0
debian/changelog

@@ -123,6 +123,9 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
     - Add new CTRL_FILE_BUILDINFO type to Dpkg::Control.
     - Add new .buildinfo fields to Dpkg::Control::Fields.
     - Add new builtin-system-build-paths Dpkg::Vendor hook.
+    - Cope gracefully with changelogs missing a timestamp trailer.
+      Based on a patch by Ian Jackson <ijackson@chiark.greenend.org.uk>.
+      Regression introduced in dpkg 1.18.8. Closes: #843248
   * Packaging:
     - Add liblocale-gettext-perl to libdpkg-perl Recommends.
     - Wrap and document dependency relationships.

+ 2 - 2
scripts/Dpkg/Changelog.pm

@@ -495,7 +495,7 @@ sub _format_dpkg {
     $f->{Distribution} = join(' ', $src->get_distributions());
     $f->{Maintainer} = $src->get_maintainer() // '';
     $f->{Date} = $src->get_timestamp() // '';
-    $f->{Timestamp} = $src->get_timepiece->epoch // '';
+    $f->{Timestamp} = $src->get_timepiece && $src->get_timepiece->epoch // '';
     $f->{Changes} = $src->get_dpkg_changes();
 
     # handle optional fields
@@ -551,7 +551,7 @@ sub _format_rfc822 {
 	$f->{Distribution} = join(' ', $entry->get_distributions());
 	$f->{Maintainer} = $entry->get_maintainer() // '';
 	$f->{Date} = $entry->get_timestamp() // '';
-	$f->{Timestamp} = $entry->get_timepiece->epoch // '';
+	$f->{Timestamp} = $entry->get_timepiece && $entry->get_timepiece->epoch // '';
 	$f->{Changes} = $entry->get_dpkg_changes();
 
 	# handle optional fields

+ 2 - 0
scripts/Dpkg/Changelog/Entry.pm

@@ -285,6 +285,8 @@ sub get_timestamp {
 
 Return the timestamp of the changelog entry as a Time::Piece object.
 
+This function might return undef if there was no timestamp.
+
 =cut
 
 sub get_timepiece {

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

@@ -393,6 +393,8 @@ sub get_timestamp {
 
 Return the timestamp of the changelog entry as a Time::Piece object.
 
+This function might return undef if there was no timestamp.
+
 =cut
 
 sub get_timepiece {

+ 3 - 2
scripts/t/Dpkg_Changelog.t

@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 92;
+use Test::More tests => 94;
 
 use File::Basename;
 
@@ -324,7 +324,8 @@ Xb-Userfield2: foobar
     }
 }
 
-foreach my $test (( [ "$datadir/misplaced-tz", 6 ])) {
+foreach my $test (([ "$datadir/misplaced-tz", 6 ],
+                   [ "$datadir/unreleased", 5, 7 ])) {
 
     my $file = shift @$test;
     my $changes = Dpkg::Changelog::Debian->new(verbose => 0);

+ 11 - 0
scripts/t/Dpkg_Changelog/unreleased

@@ -0,0 +1,11 @@
+source (2.0) UNRELEASED; urgency=medium
+
+  * This version has not been finished yet.
+
+ --
+
+source (1.0) unstable; urgency=medium
+
+  * New release.
+
+ -- Dpkg Developers <debian-dpkg@lists.debian.org>  Sat, 05 Nov 2016 18:42:23 +0100