You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2022/10/11 17:40:56 UTC

svn commit: r1904529 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Conf.pm lib/Mail/SpamAssassin/Conf/Parser.pm lib/Mail/SpamAssassin/Plugin/Check.pm t/basic_meta2.t

Author: hege
Date: Tue Oct 11 17:40:55 2022
New Revision: 1904529

URL: http://svn.apache.org/viewvc?rev=1904529&view=rev
Log:
Bug 8060 - Fix meta handling for metas without dependencies

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
    spamassassin/trunk/t/basic_meta2.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm?rev=1904529&r1=1904528&r2=1904529&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm Tue Oct 11 17:40:55 2022
@@ -4953,6 +4953,7 @@ sub new {
   # meta dependencies
   $self->{meta_dependencies} = {};
   $self->{meta_deprules} = {};
+  $self->{meta_nodeps} = {};
 
   # map eval function names to rulenames
   $self->{eval_to_rule} = {};

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm?rev=1904529&r1=1904528&r2=1904529&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm Tue Oct 11 17:40:55 2022
@@ -1136,20 +1136,22 @@ sub compile_meta_rules {
   }
 
   foreach my $name (keys %meta) {
+    if ($unsolved_metas{$name}) {
+      $conf->{meta_tests}->{$name} = sub { 0 };
+      $rule_deps{$name} = [ ];
+    }
     if (@{$rule_deps{$name}}) {
       $conf->{meta_dependencies}->{$name} = $rule_deps{$name};
       foreach my $deprule (@{$rule_deps{$name}}) {
         $conf->{meta_deprules}->{$deprule}->{$name} = 1;
       }
-    }
-    if ($unsolved_metas{$name}) {
-      $conf->{meta_tests}->{$name} = sub { 0 };
     } else {
-      # Compile meta sub
-      eval '$conf->{meta_tests}->{$name} = sub { '.$meta{$name}.'};';
-      # Paranoid check
-      die "rules: meta compilation failed for $name: '$meta{$name}': $@" if ($@);
+      $conf->{meta_nodeps}->{$name} = 1;
     }
+    # Compile meta sub
+    eval '$conf->{meta_tests}->{$name} = sub { '.$meta{$name}.'};';
+    # Paranoid check
+    die "rules: meta compilation failed for $name: '$meta{$name}': $@" if ($@);
   }
 }
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm?rev=1904529&r1=1904528&r2=1904529&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Tue Oct 11 17:40:55 2022
@@ -99,6 +99,10 @@ sub check_main {
   foreach my $rulename (keys %{$conf->{meta_tests}}) {
     $pms->{meta_pending}->{$rulename} = 1  if $conf->{scores}->{$rulename};
   }
+  # metas without dependencies are ready to be run
+  foreach my $rulename (keys %{$conf->{meta_nodeps}}) {
+    $pms->{meta_check_ready}->{$rulename} = 1;
+  }
 
   # Make sure priority -100 exists for launching DNS
   $conf->{priorities}->{-100} ||= 1 if $do_dns;

Modified: spamassassin/trunk/t/basic_meta2.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/basic_meta2.t?rev=1904529&r1=1904528&r2=1904529&view=diff
==============================================================================
--- spamassassin/trunk/t/basic_meta2.t (original)
+++ spamassassin/trunk/t/basic_meta2.t Tue Oct 11 17:40:55 2022
@@ -5,7 +5,10 @@ use lib 't';
 use SATest; sa_t_init("basic_meta2");
 
 use Test::More;
-plan tests => 20;
+
+# run many times to catch some random natured failures
+my $iterations = 5;
+plan tests => 23 * $iterations;
 
 # ---------------------------------------------------------------------------
 
@@ -24,6 +27,9 @@ plan tests => 20;
   q{ 1.0 TEST_META_E }    => '',
   q{ 1.0 TEST_META_F }    => '',
   q{ 1.0 TEST_META_G }    => '',
+  q{ 1.0 TEST_META_H }    => '',
+  q{ 1.0 TEST_META_I }    => '',
+  q{ 1.0 TEST_META_J }    => '',
 );
 
 %anti_patterns = (
@@ -54,7 +60,8 @@ tstlocalrules (qq{
    ## Unrun rule dependencies (Bug 7735)
    ##
 
-   # Non-existing rule
+   # Non-existing rule, considered "unrun" and will prevent dependent metas
+   #  from running (unless dual evaluation allows it)
    # Should not hit, meta is evaled twice: (!0) && (!1)
    meta TEST_META_2 !NONEXISTINGRULE
    # Should hit, meta is evaled twice: (!0 || 0) && (!1 || 1)
@@ -75,6 +82,14 @@ tstlocalrules (qq{
    # Should hit
    meta TEST_META_7 !TEST_DISABLED2 || TEST_DISABLED2
 
+   # Other way of "disabling" a rule, with meta 0.  This will let dependent
+   # metas run fully, as the rule is considered run but not hitting.
+   meta TEST_DISABLED3 0
+   # Should hit
+   meta TEST_META_I !TEST_DISABLED3
+   # Should hit
+   meta TEST_META_J !TEST_DISABLED3 && __FOO_1
+
    # Should not hit
    meta TEST_META_8 __FOO_1 + NONEXISTINGRULE == 2
    # Should not hit
@@ -100,8 +115,16 @@ tstlocalrules (qq{
    priority TEST_META_F 2000
    meta TEST_META_G TEST_META_C && TEST_META_D && TEST_META_E && TEST_META_F
 
+   # metas without dependencies
+   meta __TEST_META_H1  6
+   meta __TEST_META_H2  2
+   meta __TEST_META_H3  1
+   meta TEST_META_H   (__TEST_META_H1 > 2) && (__TEST_META_H2 > 1) && __TEST_META_H3
+
 });
 
-sarun ("-L -t < data/nice/001 2>&1", \&patterns_run_cb);
-ok_all_patterns();
+for (1 .. $iterations) {
+  sarun ("-L -t < data/nice/001 2>&1", \&patterns_run_cb);
+  ok_all_patterns();
+}