Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rudimentary validation of percent expansion in fields, and of the epoch

  • Loading branch information...
commit b3585e40678111522f63ceb06451738cb8f485e4 1 parent 4cd4de3
@fingolfin fingolfin authored
Showing with 44 additions and 18 deletions.
  1. +1 −0  NEWS
  2. +43 −18 perlmod/Fink/Validation.pm
View
1  NEWS
@@ -10,6 +10,7 @@ For a more comprehensive changelog of the latest experimental code, see:
feature must BuildDepend on fink (>= 0.32.0-1)
* Improved package validator to reject .deb files including .hg / .git
directories.
+ * Improved package validator to detect some issues with percent expansions.
/-------------
| fink 0.31.x (see https://github.com/fink/fink/tree/branch_0_31)
View
61 perlmod/Fink/Validation.pm
@@ -23,7 +23,7 @@
package Fink::Validation;
-use Fink::Services qw(&read_properties &read_properties_var &expand_percent &file_MD5_checksum &pkglist2lol &version_cmp);
+use Fink::Services qw(&read_properties &read_properties_var &expand_percent &expand_percent2 &file_MD5_checksum &pkglist2lol &version_cmp);
use Fink::Config qw($config);
use Cwd qw(getcwd);
use File::Find qw(find);
@@ -287,6 +287,8 @@ our %pkglist_fields = map {lc $_, 1}
'Suggests',
'Recommends',
'Enhances',
+ # 'Architecture' is not a "Depends"-style list, but its syntax is
+ # like a package-list, so piggy-back on those fields' parser
'Architecture',
);
@@ -378,7 +380,7 @@ sub validate_info_file {
my $filename = shift;
my $val_prefix = shift;
my ($properties, $info_level, $test_properties);
- my ($pkgname, $pkginvarname, $pkgversion, $pkgrevision, $pkgfullname, $pkgdestdir, $pkgpatchpath);
+ my ($pkgname, $pkginvarname, $pkgversion, $pkgrevision, $pkgepoch, $pkgfullname, $pkgdestdir, $pkgpatchpath);
my $value;
my ($basepath, $buildpath);
my ($type, $type_hash);
@@ -510,6 +512,9 @@ sub validate_info_file {
$pkgversion = '' unless defined $pkgversion;
$pkgrevision = $properties->{revision};
$pkgrevision = '' unless defined $pkgrevision;
+ $pkgepoch = $properties->{epoch};
+ $pkgepoch = '' unless defined $pkgepoch;
+ # TODO: If epoch has been specified, the pkgfullname should make use of it, too
$pkgfullname = "$pkgname-$pkgversion-$pkgrevision";
$pkgdestdir = "$buildpath/root-".$pkgfullname;
@@ -540,7 +545,14 @@ sub validate_info_file {
print "'.' and '+' ($filename)\n";
$looks_good = 0;
}
-
+ if ($pkgepoch !~ /^([1-9][0-9]*)?$/) {
+ # Strictly speaking "0" is also a legal epoch (and in fact the default epoch
+ # value), but we don't want people to add "Epoch: 0" fields to their packages,
+ # so we forbid that.
+ print "Error: Package epoch must be a positive integer ($filename)\n";
+ $looks_good = 0;
+ }
+
# TODO: figure out how to validate multivariant Type:
# - make sure syntax is okay
# - make sure each type appears as a type_*[] in Package
@@ -638,16 +650,36 @@ sub validate_info_file {
}
+ $expand = { 'n' => $pkgname,
+ 'N' => $pkgname,
+ 'v' => $pkgversion,
+ 'V' => $pkgversion,
+ 'r' => $pkgrevision,
+ 'e' => $pkgepoch,
+ 'f' => $pkgfullname,
+ 'p' => $basepath, 'P' => $basepath,
+ 'd' => $pkgdestdir,
+ 'i' => $pkgdestdir.$basepath,
+# 'a' => $pkgpatchpath,
+ 'b' => '.',
+ 'm' => $config->param('Architecture'),
+ %{$expand},
+ 'ni' => $pkginvarname,
+ 'Ni' => $pkginvarname
+ };
+
if (&validate_info_component(
properties => $properties,
filename => $filename,
info_level => $info_level,
+ expand => $expand,
) == 0) {
$looks_good = 0;
} elsif ($properties->{infotest} and &validate_info_component(
properties => $test_properties,
filename => $filename,
info_level => $info_level,
+ expand => $expand,
is_infotest => 1,
) == 0) {
$looks_good = 0;
@@ -737,6 +769,7 @@ sub validate_info_file {
splitoff_field => $splitoff_field,
filename => $filename,
info_level => $info_level,
+ expand => { 'N' => $pkgname, %{$expand} },
builddepends => $properties->{builddepends},
) == 0) {
$looks_good = 0;
@@ -809,21 +842,6 @@ sub validate_info_file {
}
}
- $expand = { 'n' => $pkgname,
- 'v' => $pkgversion,
- 'r' => $pkgrevision,
- 'f' => $pkgfullname,
- 'p' => $basepath, 'P' => $basepath,
- 'd' => $pkgdestdir,
- 'i' => $pkgdestdir.$basepath,
-# 'a' => $pkgpatchpath,
- 'b' => '.',
- 'm' => $config->param('Architecture'),
- %{$expand},
- 'ni' => $pkginvarname,
- 'Ni' => $pkginvarname
- };
-
my %patchfile_fields = map { lc $_, 1 } grep { /^patchfile(|[2-9]|[1-9]\d+)$/ } keys %$properties;
my %patchfile_md5_fields = map { lc $_, 1 } grep { /^patchfile(|[2-9]|[1-9]\d+)-md5$/ } keys %$properties;
@@ -1082,6 +1100,7 @@ sub validate_info_component {
my $splitoff_field = $options{splitoff_field};
my $filename = $options{filename};
my $info_level = $options{info_level};
+ my $expand = $options{expand};
my $is_infotest = $options{is_infotest};
# make sure this $option is available even in parent
@@ -1202,6 +1221,12 @@ sub validate_info_component {
$looks_good = 0;
}
}
+
+ # verify only well-defined percent expansions are used.
+ &expand_percent2($value, $expand,
+ 'err_action' => 'undef',
+ 'err_info' => $filename.' '.$field );
+
foreach my $atom (split /[,|]/, $pkglist) {
$atom =~ s/\A\s*//;
$atom =~ s/\s*\Z//;
Please sign in to comment.
Something went wrong with that request. Please try again.