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

Dpkg::Deps: fix dependency parsing code

Fix dependency parsing code in Dpkg::Deps to not accept "foo\nbar"
even if foo is valid. A regex was improperly matching "\n" as
end of string due to usage of the "m" modifier.

Also improve the warning displayed when the dependency can't be parsed.

Add a non-regression test to ensure that this problem doesn't come back.

Reported-by: Andrew Sayers <andrew-dpkg@pileofstuff.org>
Raphael Hertzog лет назад: 17
Родитель
Сommit
fe930e9bb3
3 измененных файлов с 11 добавлено и 3 удалено
  1. 3 0
      debian/changelog
  2. 2 2
      scripts/Dpkg/Deps.pm
  3. 6 1
      scripts/t/400_Dpkg_Deps.t

+ 3 - 0
debian/changelog

@@ -40,6 +40,9 @@ dpkg (1.15.3) UNRELEASED; urgency=low
     (recognized by ~bpo or ~vola in their version number). Closes: #525115
   * Support all checksum algorithms in dpkg-scanpackages/dpkg-scansources.
     Closes: #533828
+  * Fix dependency parsing code in Dpkg::Deps to not accept "foo\nbar"
+    even if foo is valid. Closes: #534464
+    Thanks to Andrew Sayers for spotting the problem.
 
   [ Joachim Breitner ]
   * Warn about unused substvars in dpkg-gencontrol. Closes: #532760

+ 2 - 2
scripts/Dpkg/Deps.pm

@@ -317,7 +317,7 @@ sub parse {
         foreach my $dep_or (split(/\s*\|\s*/m, $dep_and)) {
 	    my $dep_simple = Dpkg::Deps::Simple->new($dep_or);
 	    if (not defined $dep_simple->{package}) {
-		warning(_g("can't parse dependency %s"), $dep_and);
+		warning(_g("can't parse dependency %s"), $dep_or);
 		return undef;
 	    }
 	    $dep_simple->{arches} = undef if not $options{use_arch};
@@ -555,7 +555,7 @@ sub parse {
                 \s* \]                      # closing bracket
               )?                            # end of optional architecture
 	      \s*$			    # trailing spaces at end
-            /mx;
+            /x;
     $self->{package} = $1;
     $self->{relation} = $2;
     $self->{version} = $3;

+ 6 - 1
scripts/t/400_Dpkg_Deps.t

@@ -1,6 +1,6 @@
 # -*- mode: cperl;-*-
 
-use Test::More tests => 15;
+use Test::More tests => 16;
 
 use strict;
 use warnings;
@@ -63,3 +63,8 @@ is($dep_empty1->dump(), "", "Empty dependency");
 my $dep_empty2 = Dpkg::Deps::parse(" , , ", union => 1);
 is($dep_empty2->dump(), "", "' , , ' is also an empty dependency");
 
+$SIG{'__WARN__'} = sub {};
+my $dep_bad_multiline = Dpkg::Deps::parse("a, foo\nbar, c");
+ok(!defined($dep_bad_multiline), "invalid dependency split over multiple line");
+delete $SIG{'__WARN__'};
+