ソースを参照

Dpkg::Source::Package: Do not scan control file twice for PGP signature

The code was pre-scanning the control file looking for a PGP signature,
and the parser was doing a more thorough check later on. Just remove the
double parsing, and rely on the more accurate one from the parser.
Guillem Jover 13 年 前
コミット
bb38862b4a
共有3 個のファイルを変更した5 個の追加12 個の削除を含む
  1. 1 0
      debian/changelog
  2. 3 3
      scripts/Dpkg/Control/HashCore.pm
  3. 1 9
      scripts/Dpkg/Source/Package.pm

+ 1 - 0
debian/changelog

@@ -140,6 +140,7 @@ dpkg (1.17.0) UNRELEASED; urgency=low
     which might be problematic when cross-compiling. Closes: #698881
   * Only apply empy line and comma cleanups when doing substvar replacements
     on fields where those are relevant. Closes: #659814
+  * Do not scan control files twice for PGP signature presence.
 
   [ Raphaël Hertzog ]
   * Fix dpkg-maintscript-helper rm_conffile and mv_conffile to do nothing

+ 3 - 3
scripts/Dpkg/Control/HashCore.pm

@@ -105,6 +105,7 @@ sub new {
     my $self = \{
         in_order => [],
         out_order => [],
+        is_pgp_signed => 0,
         allow_pgp => 0,
         allow_duplicate => 0,
         drop_empty => 0,
@@ -172,7 +173,6 @@ sub parse {
     my $parabody = 0;
     my $cf; # Current field
     my $expect_pgp_sig = 0;
-    my $pgp_signed = 0;
 
     while (<$fh>) {
 	s/\s*\n$//;
@@ -229,7 +229,7 @@ sub parse {
                 }
 		# This does not mean the signature is correct, that needs to
 		# be verified by gnupg.
-		$pgp_signed = 1;
+		$$self->{is_pgp_signed} = 1;
 	    }
 	    last; # Finished parsing one block
 	} else {
@@ -238,7 +238,7 @@ sub parse {
 	}
     }
 
-    if ($expect_pgp_sig and not $pgp_signed) {
+    if ($expect_pgp_sig and not $$self->{is_pgp_signed}) {
         syntaxerr($desc, _g('unfinished PGP signature'));
     }
 

+ 1 - 9
scripts/Dpkg/Source/Package.pm

@@ -189,19 +189,11 @@ sub initialize {
     $self->{basedir} = $dir || './';
     $self->{filename} = $fn;
 
-    # Check if it contains a signature
-    open(my $dsc_fh, '<', $filename) || syserr(_g('cannot open %s'), $filename);
-    $self->{is_signed} = 0;
-    while (<$dsc_fh>) {
-        next if /^\s*$/o;
-        $self->{is_signed} = 1 if /^-----BEGIN PGP SIGNED MESSAGE-----\s*$/o;
-        last;
-    }
-    close($dsc_fh);
     # Read the fields
     my $fields = Dpkg::Control->new(type => CTRL_PKG_SRC);
     $fields->load($filename);
     $self->{fields} = $fields;
+    $self->{is_signed} = $fields->get_option('is_pgp_signed');
 
     foreach my $f (qw(Source Version Files)) {
         unless (defined($fields->{$f})) {