summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2017-12-10 12:07:42 +0100
committerGuillem Jover <guillem@debian.org>2018-01-16 11:24:54 +0100
commit2f5816d8be40b449d2473b22f9e0c33b32f3bd78 (patch)
treeaadb98654b08bd03c92869aaaa6cd143af308369
parent797ed78bd87c77b6fa9c3867d0fefa90bb21014c (diff)
downloaddpkg-2f5816d8be40b449d2473b22f9e0c33b32f3bd78.tar.gz
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
-rw-r--r--debian/changelog3
-rw-r--r--scripts/Dpkg/Arch.pm28
-rwxr-xr-xscripts/dpkg-genchanges.pl4
-rwxr-xr-xscripts/dpkg-gencontrol.pl2
-rw-r--r--scripts/t/Dpkg_Arch.t9
5 files changed, 36 insertions, 10 deletions
diff --git a/debian/changelog b/debian/changelog
index 9b6533fc9..2d4f616f2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -18,6 +18,8 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
Reported by Jakub Wilk <jwilk@jwilk.net>.
* Add new AS, STRIP, OBJCOPY, OBJDUMP, NM, AR and RANLIB buildtools
variables to buildtools.mk. Prompted by Helmut Grohne <helmut@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@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@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 c3e891526..14709d6cc 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 84bdc4ba6..4f4b33608 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 2e656a246..1c92e66dd 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 525817085..0ef9d1899 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');
+@arch_ref = qw(amd64 arm64 linux-i386 kfreebsd-any);
+@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');