Quellcode durchsuchen

Dpkg::Index: Check existence of search criteria

When checking a regex or a string match we should avoid comparing
against undefined fields, as those produce perl warnings, and will
never match anyway.

We leave the CODE references alone, as the caller might want to check
if the field value is undefined.

Closes: #780906
Based-on-patch-by: Daniel Dehennin <daniel.dehennin@baby-gnu.org>
Guillem Jover vor 10 Jahren
Ursprung
Commit
40f5f8f76b
2 geänderte Dateien mit 7 neuen und 2 gelöschten Zeilen
  1. 3 0
      debian/changelog
  2. 4 2
      scripts/Dpkg/Index.pm

+ 3 - 0
debian/changelog

@@ -50,6 +50,9 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
     - Only warn once when a diff patches a file multiple times in
     - Only warn once when a diff patches a file multiple times in
       Dpkg::Source::Patch, and fix the warning message to make it clear that
       Dpkg::Source::Patch, and fix the warning message to make it clear that
       the diff might be patchig the file more than once, not just twice.
       the diff might be patchig the file more than once, not just twice.
+    - Check existence of search criteria in Dpkg::Index when checking with a
+      regex or a string match. Closes: #780906
+      Base on a patch by Daniel Dehennin <daniel.dehennin@baby-gnu.org>.
   * Build system:
   * Build system:
     - Fix building development documentation.
     - Fix building development documentation.
   * Test suite:
   * Test suite:

+ 4 - 2
scripts/Dpkg/Index.pm

@@ -227,7 +227,8 @@ sub get_keys {
     foreach my $s_crit (keys %crit) { # search criteria
     foreach my $s_crit (keys %crit) { # search criteria
 	if (ref($crit{$s_crit}) eq 'Regexp') {
 	if (ref($crit{$s_crit}) eq 'Regexp') {
 	    @selected = grep {
 	    @selected = grep {
-		$self->{items}{$_}{$s_crit} =~ $crit{$s_crit}
+		exists $self->{items}{$_}{$s_crit} and
+		       $self->{items}{$_}{$s_crit} =~ $crit{$s_crit}
 	    } @selected;
 	    } @selected;
 	} elsif (ref($crit{$s_crit}) eq 'CODE') {
 	} elsif (ref($crit{$s_crit}) eq 'CODE') {
 	    @selected = grep {
 	    @selected = grep {
@@ -235,7 +236,8 @@ sub get_keys {
 	    } @selected;
 	    } @selected;
 	} else {
 	} else {
 	    @selected = grep {
 	    @selected = grep {
-		$self->{items}{$_}{$s_crit} eq $crit{$s_crit}
+		exists $self->{items}{$_}{$s_crit} and
+		       $self->{items}{$_}{$s_crit} eq $crit{$s_crit}
 	    } @selected;
 	    } @selected;
 	}
 	}
     }
     }