[dpkg] 19/28: scripts: Reject negated values in Architecture field

Mattia Rizzolo mattia at debian.org
Mon Jan 22 17:11:24 UTC 2018


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch master
in repository dpkg.

commit 2f5816d8be40b449d2473b22f9e0c33b32f3bd78
Author: Guillem Jover <guillem at debian.org>
Date:   Sun Dec 10 12:07:42 2017 +0100

    scripts: Reject negated values in Architecture field
    
    Add new positive options argument to arch validators, as the Architecture
    field should not accept negated architectures. We preserve the current
    functions default behavior and add a new option to control whether to
    reject negated architectures.
    
    Fixes: commit d355b340f3a6cde7fc1cb5649d82fbebd3b97ea1
    Stable-Candidate: 1.18.x
---
 debian/changelog           |  3 +++
 scripts/Dpkg/Arch.pm       | 28 ++++++++++++++++++++++------
 scripts/dpkg-genchanges.pl |  4 ++--
 scripts/dpkg-gencontrol.pl |  2 +-
 scripts/t/Dpkg_Arch.t      |  9 ++++++++-
 5 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 9b6533f..2d4f616 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -18,6 +18,8 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     Reported by Jakub Wilk <jwilk at jwilk.net>.
   * Add new AS, STRIP, OBJCOPY, OBJDUMP, NM, AR and RANLIB buildtools
     variables to buildtools.mk. Prompted by Helmut Grohne <helmut at subdivi.de>.
+  * Restore rejecting negated architectures in Architecture field in
+    dpkg-gencontrol and dpkg-genchanges. Regression introduced in dpkg 1.18.5.
   * Perl modules:
     - Check that $tarname is defined before use in Dpkg::Source::Package::V1.
       Thanks to Christoph Biedl <debian.axhn at manchmal.in-ulm.de>.
@@ -30,6 +32,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     - Check that $state->{seen} exists instead of $state being just defined.
       Fixes regression in dpkg-gensymbols symbols output.
       Thanks to Dmitry Shachnev <mitya57 at debian.org>. Closes: #880166
+    - Add new positive options argument to arch validators in Dpkg::Arch.
   * Documentation:
     - Update gettext minimal version in README.
     - Add a missing dot on the dpkg-buildflags(1) «lfs» feature paragraph.
diff --git a/scripts/Dpkg/Arch.pm b/scripts/Dpkg/Arch.pm
index c3e8915..14709d6 100644
--- a/scripts/Dpkg/Arch.pm
+++ b/scripts/Dpkg/Arch.pm
@@ -36,7 +36,7 @@ use strict;
 use warnings;
 use feature qw(state);
 
-our $VERSION = '1.02';
+our $VERSION = '1.03';
 our @EXPORT_OK = qw(
     get_raw_build_arch
     get_raw_host_arch
@@ -599,17 +599,25 @@ sub debarch_is_wildcard($)
     return 0;
 }
 
-=item $bool = debarch_is_illegal($arch)
+=item $bool = debarch_is_illegal($arch, %options)
 
 Validate an architecture name.
 
+If the "positive" option is set to a true value, only positive architectures
+will be accepted, otherwise negated architectures are allowed.
+
 =cut
 
 sub debarch_is_illegal
 {
-    my ($arch) = @_;
+    my ($arch, %opts) = @_;
+    my $arch_re = qr/[a-zA-Z0-9][a-zA-Z0-9-]*/;
 
-    return $arch !~ m/^!?[a-zA-Z0-9][a-zA-Z0-9-]*$/;
+    if ($opts{positive}) {
+        return $arch !~ m/^$arch_re$/;
+    } else {
+        return $arch !~ m/^!?$arch_re$/;
+    }
 }
 
 =item $bool = debarch_is_concerned($arch, @arches)
@@ -651,15 +659,18 @@ sub debarch_is_concerned
 
 Parse an architecture list.
 
+If the "positive" option is set to a true value, only positive architectures
+will be accepted, otherwise negated architectures are allowed.
+
 =cut
 
 sub debarch_list_parse
 {
-    my $arch_list = shift;
+    my ($arch_list, %opts) = @_;
     my @arch_list = split ' ', $arch_list;
 
     foreach my $arch (@arch_list) {
-        if (debarch_is_illegal($arch)) {
+        if (debarch_is_illegal($arch, %opts)) {
             error(g_("'%s' is not a legal architecture in list '%s'"),
                   $arch, $arch_list);
         }
@@ -676,6 +687,11 @@ __END__
 
 =head1 CHANGES
 
+=head2 Version 1.03 (dpkg 1.19.1)
+
+New argument: Accept a "positive" option in debarch_is_illegal() and
+debarch_list_parse().
+
 =head2 Version 1.02 (dpkg 1.18.19)
 
 New import tags: ":all", ":getters", ":parsers", ":mappers", ":operators".
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index 84bdc4b..4f4b336 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -369,7 +369,7 @@ foreach my $pkg ($control->get_packages()) {
 	# No files for this package... warn if it's unexpected
 	if (((build_has_any(BUILD_ARCH_INDEP) and debarch_eq('all', $a)) or
 	     (build_has_any(BUILD_ARCH_DEP) and
-	      (any { debarch_is($host_arch, $_) } debarch_list_parse($a)))) and
+	      (any { debarch_is($host_arch, $_) } debarch_list_parse($a, positive => 1)))) and
 	    (@restrictions == 0 or
 	     evaluate_restriction_formula(\@restrictions, \@profiles)))
 	{
@@ -388,7 +388,7 @@ foreach my $pkg ($control->get_packages()) {
 	    $f2pricf{$_} = $v foreach (@f);
 	} elsif (m/^Architecture$/) {
 	    if (build_has_any(BUILD_ARCH_DEP) and
-	        (any { debarch_is($host_arch, $_) } debarch_list_parse($v))) {
+	        (any { debarch_is($host_arch, $_) } debarch_list_parse($v, positive => 1))) {
 		$v = $host_arch;
 	    } elsif (!debarch_eq('all', $v)) {
 		$v = '';
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl
index 2e656a2..1c92e66 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -217,7 +217,7 @@ foreach (keys %{$pkg}) {
 	if (debarch_eq('all', $v)) {
 	    $fields->{$_} = $v;
 	} else {
-	    my @archlist = debarch_list_parse($v);
+	    my @archlist = debarch_list_parse($v, positive => 1);
 
 	    if (none { debarch_is($host_arch, $_) } @archlist) {
 		error(g_("current host architecture '%s' does not " .
diff --git a/scripts/t/Dpkg_Arch.t b/scripts/t/Dpkg_Arch.t
index 5258170..0ef9d18 100644
--- a/scripts/t/Dpkg_Arch.t
+++ b/scripts/t/Dpkg_Arch.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16367;
+use Test::More tests => 16369;
 
 use_ok('Dpkg::Arch', qw(debarch_to_debtuple debarch_to_multiarch
                         debarch_eq debarch_is debarch_is_wildcard
@@ -148,9 +148,16 @@ my @arch_ref;
 @arch_new = debarch_list_parse('amd64  !arm64   linux-i386 !kfreebsd-any');
 is_deeply(\@arch_new, \@arch_ref, 'parse valid arch list');
 
+ at arch_ref = qw(amd64 arm64 linux-i386 kfreebsd-any);
+ at arch_new = debarch_list_parse('amd64  arm64   linux-i386 kfreebsd-any', positive => 1);
+is_deeply(\@arch_new, \@arch_ref, 'parse valid positive arch list');
+
 eval { @arch_new = debarch_list_parse('!amd64!arm64') };
 ok($@, 'parse concatenated arches failed');
 
+eval { @arch_new = debarch_list_parse('amd64 !arm64 !mips', positive => 1) };
+ok($@, 'parse disallowed negated arches failed');
+
 is(debarch_to_abiattrs(undef), undef, 'undef ABI attrs');
 is_deeply([ debarch_to_abiattrs('amd64') ], [ qw(64 little) ], 'amd64 ABI attrs');
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list