Mailing List Archive

svn commit: r330694 - in /spamassassin/trunk/lib/Mail/SpamAssassin: Conf.pm Conf/Parser.pm
Author: dos
Date: Thu Nov 3 19:04:38 2005
New Revision: 330694

URL: http://svn.apache.org/viewcvs?rev=330694&view=rev
Log:
bug 4648: validate rule names

Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm?rev=330694&r1=330693&r2=330694&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm Thu Nov 3 19:04:38 2005
@@ -1743,7 +1743,7 @@
If the C<[if-unset: STRING]> tag is present, then C<STRING> will
be used if the header is not found in the mail message.

-Test names should not start with a number, and must contain only
+Test names must not start with a number, and must contain only
alphanumerics and underscores. It is suggested that lower-case characters
not be used, and names have a length of no more than 22 characters,
as an informal convention. Dashes are not allowed.

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm?rev=330694&r1=330693&r2=330694&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm Thu Nov 3 19:04:38 2005
@@ -533,13 +533,6 @@
my ($k, $v);

while ( ($k,$v) = each %{$conf->{tests}} ) {
- if ($conf->{lint_rules}) {
- if (length($k) > 50 && $k !~ /^__/ && $k !~ /^T_/) {
- warn "config: warning: rule name '$k' is over 50 chars\n";
- $conf->{errors}++;
- }
- }
-
if ( ! exists $conf->{scores}->{$k} ) {
# T_ rules (in a testing probationary period) get low, low scores
my $set_score = ($k =~/^T_/) ? 0.01 : 1.0;
@@ -771,10 +764,30 @@
my $conf = $self->{conf};

# Don't allow invalid names ...
- if ($name !~ /^\w+$/) {
- warn "config: error: rule '$name' has invalid characters (not Alphanumeric + Underscore)\n";
+ if ($name !~ /^\D\w*$/) {
+ warn "config: error: rule '$name' has invalid characters ".
+ "(not Alphanumeric + Underscore + starting with a non-digit)\n";
$conf->{errors}++;
return;
+ }
+
+ # Also set a hard limit for ALL rules (rule names longer than 242
+ # characters throw warnings). Check this separately from the above
+ # pattern to avoid vague error messages.
+ if (length $name > 200) {
+ warn "config: error: rule '$name' is way too long ".
+ "(recommended maximum length is 22 characters)\n";
+ $conf->{errors}++;
+ return;
+ }
+
+ # Warn about, but use, long rule names during --lint
+ if ($conf->{lint_rules}) {
+ if (length($name) > 50 && $name !~ /^__/ && $name !~ /^T_/) {
+ warn "config: warning: rule name '$name' is over 50 chars ".
+ "(recommended maximum length is 22 characters)\n";
+ $conf->{errors}++;
+ }
}

# all of these rule types are regexps