소스 검색

Dpkg::Deps: Validate architecture arguments in deps_parse()

This function only works with real and known Debian architectures. It
will not work with wildcards, nor the special architectures 'all' nor
'source'. Validate the arguments and croak early on to spot bogus usage.

Prompted-by: Johannes Schauer <josch@debian.org>
Guillem Jover 9 년 전
부모
커밋
d3d4348c31
3개의 변경된 파일31개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 0
      debian/changelog
  2. 8 1
      scripts/Dpkg/Deps.pm
  3. 20 1
      scripts/t/Dpkg_Deps.t

+ 3 - 0
debian/changelog

@@ -5,6 +5,9 @@ dpkg (1.18.15) UNRELEASED; urgency=medium
     - Do not enable PIE when linking static programs. glibc-based systems
       do not support this combination and produce very bogus output.
       Proposed by Szabolcs Nagy <nsz@port70.net>. Closes: #843714
+  * Perl modules:
+    - Validate architecture arguments in Dpkg::Deps deps_parse().
+      Prompted by Johannes Schauer <josch@debian.org>.
   * Test suite:
     - Mark partially documented POD modules as TAP TODO.
 

+ 8 - 1
scripts/Dpkg/Deps.pm

@@ -58,10 +58,11 @@ our @EXPORT = qw(
     deps_compare
 );
 
+use Carp;
 use Exporter qw(import);
 
 use Dpkg::Version;
-use Dpkg::Arch qw(get_host_arch get_build_arch);
+use Dpkg::Arch qw(get_host_arch get_build_arch debarch_to_debtuple);
 use Dpkg::BuildProfiles qw(get_build_profiles);
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
@@ -250,6 +251,12 @@ working with dependency fields from F<debian/tests/control>.
 sub deps_parse {
     my ($dep_line, %options) = @_;
 
+    # Validate arguments.
+    croak "invalid host_arch $options{host_arch}"
+        if defined $options{host_arch} and not defined debarch_to_debtuple($options{host_arch});
+    croak "invalid biuild_arch $options{build_arch}"
+        if defined $options{build_arch} and not defined debarch_to_debtuple($options{build_arch});
+
     $options{use_arch} //= 1;
     $options{reduce_arch} //= 0;
     $options{host_arch} //= get_host_arch();

+ 20 - 1
scripts/t/Dpkg_Deps.t

@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 62;
+use Test::More tests => 70;
 
 use Dpkg::Arch qw(get_host_arch);
 use Dpkg::Version;
@@ -30,6 +30,25 @@ is(deps_concat('', undef), '', 'Concatenate empty string with undef');
 is(deps_concat('dep-a', undef, 'dep-b'), 'dep-a, dep-b',
    'Concatenate two strings with intermixed undef');
 
+sub test_dep_parse_option {
+    my %options = @_;
+
+    eval {
+        my $dep_croak = deps_parse('pkg', %options);
+    };
+    my $options = join ' ', map { "$_=$options{$_}" } keys %options;
+    ok(defined $@, "Parse with bogus arch options $options");
+}
+
+test_dep_parse_option(host_arch => 'all');
+test_dep_parse_option(host_arch => 'any');
+test_dep_parse_option(host_arch => 'linux-any');
+test_dep_parse_option(host_arch => 'unknown-arch');
+test_dep_parse_option(build_arch => 'all');
+test_dep_parse_option(build_arch => 'any');
+test_dep_parse_option(build_arch => 'linux-any');
+test_dep_parse_option(build_arch => 'unknown-arch');
+
 my $field_multiline = ' , , libgtk2.0-common (= 2.10.13-1)  , libatk1.0-0 (>=
 1.13.2), libc6 (>= 2.5-5), libcairo2 (>= 1.4.0), libcupsys2 (>= 1.2.7),
 libfontconfig1 (>= 2.4.0), libglib2.0-0  (  >= 2.12.9), libgnutls13 (>=