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: $!"; |