View | Details | Raw Unified | Return to bug 7496
Collapse All | Expand All

(-)a/lib/Mail/SpamAssassin/Conf/Parser.pm (-11 / +16 lines)
Lines 263-268 sub parse { Link Here
263
  while (defined ($line = shift @conf_lines)) {
263
  while (defined ($line = shift @conf_lines)) {
264
    local ($1);         # bug 3838: prevent random taint flagging of $1
264
    local ($1);         # bug 3838: prevent random taint flagging of $1
265
265
266
   if (index($line,'#') > -1) {
266
    # bug 5545: used to support testing rules in the ruleqa system
267
    # bug 5545: used to support testing rules in the ruleqa system
267
    if ($keepmetadata && $line =~ /^\#testrules/) {
268
    if ($keepmetadata && $line =~ /^\#testrules/) {
268
      $self->{file_scoped_attrs}->{testrules}++;
269
      $self->{file_scoped_attrs}->{testrules}++;
Lines 278-285 sub parse { Link Here
278
279
279
    $line =~ s/(?<!\\)#.*$//; # remove comments
280
    $line =~ s/(?<!\\)#.*$//; # remove comments
280
    $line =~ s/\\#/#/g; # hash chars are escaped, so unescape them
281
    $line =~ s/\\#/#/g; # hash chars are escaped, so unescape them
282
   }
283
284
   if ($line =~ tr{ \t\r\n\f}{}) {
281
    $line =~ s/^\s+//;  # remove leading whitespace
285
    $line =~ s/^\s+//;  # remove leading whitespace
282
    $line =~ s/\s+$//;  # remove tailing whitespace
286
    $line =~ s/\s+$//;  # remove tailing whitespace
287
  }
283
    next unless($line); # skip empty lines
288
    next unless($line); # skip empty lines
284
289
285
    # handle i18n
290
    # handle i18n
Lines 288-294 sub parse { Link Here
288
    my($key, $value) = split(/\s+/, $line, 2);
293
    my($key, $value) = split(/\s+/, $line, 2);
289
    $key = lc $key;
294
    $key = lc $key;
290
    # convert all dashes in setting name to underscores.
295
    # convert all dashes in setting name to underscores.
291
    $key =~ s/-/_/g;
296
    $key =~ tr/-/_/;
292
    $value = '' unless defined($value);
297
    $value = '' unless defined($value);
293
298
294
#   # Do a better job untainting this info ...
299
#   # Do a better job untainting this info ...
Lines 338-363 sub parse { Link Here
338
    }
343
    }
339
344
340
    # now handle the commands.
345
    # now handle the commands.
341
    if ($key eq 'include') {
346
    elsif ($key eq 'include') {
342
      $value = $self->fix_path_relative_to_current_file($value);
347
      $value = $self->fix_path_relative_to_current_file($value);
343
      my $text = $conf->{main}->read_cf($value, 'included file');
348
      my $text = $conf->{main}->read_cf($value, 'included file');
344
      unshift (@conf_lines, split (/\n/, $text));
349
      unshift (@conf_lines, split (/\n/, $text));
345
      next;
350
      next;
346
    }
351
    }
347
352
348
    if ($key eq 'ifplugin') {
353
    elsif ($key eq 'ifplugin') {
349
      $self->handle_conditional ($key, "plugin ($value)",
354
      $self->handle_conditional ($key, "plugin ($value)",
350
                        \@if_stack, \$skip_parsing);
355
                        \@if_stack, \$skip_parsing);
351
      next;
356
      next;
352
    }
357
    }
353
358
354
    if ($key eq 'if') {
359
    elsif ($key eq 'if') {
355
      $self->handle_conditional ($key, $value,
360
      $self->handle_conditional ($key, $value,
356
                        \@if_stack, \$skip_parsing);
361
                        \@if_stack, \$skip_parsing);
357
      next;
362
      next;
358
    }
363
    }
359
364
360
    if ($key eq 'else') {
365
    elsif ($key eq 'else') {
361
      # TODO: if/else/else won't get flagged here :(
366
      # TODO: if/else/else won't get flagged here :(
362
      if (!@if_stack) {
367
      if (!@if_stack) {
363
        $parse_error = "config: found else without matching conditional";
368
        $parse_error = "config: found else without matching conditional";
Lines 369-375 sub parse { Link Here
369
    }
374
    }
370
375
371
    # and the endif statement:
376
    # and the endif statement:
372
    if ($key eq 'endif') {
377
    elsif ($key eq 'endif') {
373
      my $lastcond = pop @if_stack;
378
      my $lastcond = pop @if_stack;
374
      if (!defined $lastcond) {
379
      if (!defined $lastcond) {
375
        $parse_error = "config: found endif without matching conditional";
380
        $parse_error = "config: found endif without matching conditional";
Lines 508-514 sub handle_conditional { Link Here
508
  my $conf = $self->{conf};
513
  my $conf = $self->{conf};
509
514
510
  my $lexer = ARITH_EXPRESSION_LEXER;
515
  my $lexer = ARITH_EXPRESSION_LEXER;
511
  my @tokens = ($value =~ m/($lexer)/g);
516
  my @tokens = ($value =~ m/($lexer)/og);
512
517
513
  my $eval = '';
518
  my $eval = '';
514
  my $bad = 0;
519
  my $bad = 0;
Lines 984-997 sub _meta_deps_recurse { Link Here
984
989
985
  # Lex the rule into tokens using a rather simple RE method ...
990
  # Lex the rule into tokens using a rather simple RE method ...
986
  my $lexer = ARITH_EXPRESSION_LEXER;
991
  my $lexer = ARITH_EXPRESSION_LEXER;
987
  my @tokens = ($rule =~ m/$lexer/g);
992
  my @tokens = ($rule =~ m/$lexer/og);
988
993
989
  # Go through each token in the meta rule
994
  # Go through each token in the meta rule
990
  my $conf_tests = $conf->{tests};
995
  my $conf_tests = $conf->{tests};
991
  foreach my $token (@tokens) {
996
  foreach my $token (@tokens) {
992
    # has to be an alpha+numeric token
997
    # has to be an alpha+numeric token
993
  # next if $token =~ /^(?:\W+|[+-]?\d+(?:\.\d+)?)$/;
998
    next if $token =~ tr{A-Za-z0-9_}{}c || substr($token,0,1) =~ tr{A-Za-z_}{}c; # even faster
994
    next if $token !~ /^[A-Za-z_][A-Za-z0-9_]*\z/s;  # faster
999
995
    # and has to be a rule name
1000
    # and has to be a rule name
996
    next unless exists $conf_tests->{$token};
1001
    next unless exists $conf_tests->{$token};
997
1002
Lines 1291-1297 sub is_meta_valid { Link Here
1291
1296
1292
  # Lex the rule into tokens using a rather simple RE method ...
1297
  # Lex the rule into tokens using a rather simple RE method ...
1293
  my $lexer = ARITH_EXPRESSION_LEXER;
1298
  my $lexer = ARITH_EXPRESSION_LEXER;
1294
  my @tokens = ($rule =~ m/$lexer/g);
1299
  my @tokens = ($rule =~ m/$lexer/og);
1295
  if (length($name) == 1) {
1300
  if (length($name) == 1) {
1296
    for (@tokens) {
1301
    for (@tokens) {
1297
      print "$name $_\n "  or die "Error writing token: $!";
1302
      print "$name $_\n "  or die "Error writing token: $!";
(-)a/lib/Mail/SpamAssassin/Plugin/Check.pm (-4 / +3 lines)
Lines 534-540 sub do_meta_tests { Link Here
534
534
535
    # Lex the rule into tokens using a rather simple RE method ...
535
    # Lex the rule into tokens using a rather simple RE method ...
536
    my $lexer = ARITH_EXPRESSION_LEXER;
536
    my $lexer = ARITH_EXPRESSION_LEXER;
537
    my @tokens = ($rule =~ m/$lexer/g);
537
    my @tokens = ($rule =~ m/$lexer/og);
538
538
539
    # Set the rule blank to start
539
    # Set the rule blank to start
540
    $meta{$rulename} = "";
540
    $meta{$rulename} = "";
Lines 546-553 sub do_meta_tests { Link Here
546
    foreach my $token (@tokens) {
546
    foreach my $token (@tokens) {
547
547
548
      # Numbers can't be rule names
548
      # Numbers can't be rule names
549
    # if ($token =~ /^(?:\W+|[+-]?\d+(?:\.\d+)?)$/) {
549
      if ($token =~ tr{A-Za-z0-9_}{}c || substr($token,0,1) =~ tr{A-Za-z_}{}c) {
550
      if ($token !~ /^[A-Za-z_][A-Za-z0-9_]*\z/s) {  # faster
551
        $meta{$rulename} .= "$token ";
550
        $meta{$rulename} .= "$token ";
552
      }
551
      }
553
      else {  # token is a rule name
552
      else {  # token is a rule name
Lines 613-619 sub do_meta_tests { Link Here
613
          warn "no meta_dependencies defined for $metas[$i]";
612
          warn "no meta_dependencies defined for $metas[$i]";
614
        }
613
        }
615
        my $alldeps = join ' ', grep {
614
        my $alldeps = join ' ', grep {
616
                ($tflags->{$_}||'') =~ /\bnet\b/
615
                index( ($tflags->{$_}||''),'net') > -1 && ($tflags->{$_}||'') =~ /\bnet\b/
617
              } split (' ', $conf->{meta_dependencies}->{ $metas[$i] } );
616
              } split (' ', $conf->{meta_dependencies}->{ $metas[$i] } );
618
617
619
        if ($alldeps ne '') {
618
        if ($alldeps ne '') {
(-)a/lib/Mail/SpamAssassin/Util.pm (-5 / +1 lines)
Lines 327-337 sub untaint_hostname { Link Here
327
sub untaint_var {
327
sub untaint_var {
328
# my $arg = $_[0];  # avoid copying unnecessarily
328
# my $arg = $_[0];  # avoid copying unnecessarily
329
  if (!ref $_[0]) { # optimized by-far-the-most-common case
329
  if (!ref $_[0]) { # optimized by-far-the-most-common case
330
    no re 'taint';  # override a  "use re 'taint'"  from outer scope
330
    return defined $_[0] ? scalar each %{ { $_[0] => undef } } : undef; ## no critic (ProhibitExplicitReturnUndef)  - See Bug 7120 - fast untaint (hash keys cannot be tainted)
331
    return undef if !defined $_[0]; ## no critic (ProhibitExplicitReturnUndef)  - See Bug 7120
332
    local($1); # avoid Perl taint bug: tainted global $1 propagates taintedness
333
    $_[0] =~ /^(.*)\z/s;
334
    return $1;
335
  } else {
331
  } else {
336
    my $r = ref $_[0];
332
    my $r = ref $_[0];
337
    if ($r eq 'ARRAY') {
333
    if ($r eq 'ARRAY') {

Return to bug 7496