mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 18:48:20 +00:00
parse.y/directives: Reject directives as statements
Avoid the issue outlined in #2289 where the @if or @else is taken as the statement of an `if`, `for` or `while` by rejecting such constructs. Effectively this means the following scripts are now rejected: # Print's "cond true" with Zeek 5.0 even though the `if ( F )` # should be in effect. if ( F ) @if ( T ) print "cond true"; @else print "cond false"; @endif or # Print's "hello" once with Zeek 5.0 local v = vector( 1, 2, 3 ); for ( i in v ) @if ( T ) print("hello") @endif To make above work as intended, additional braces can be used. if ( T ) { @if ( cond ) print "cond true"; @else print "cond false"; @endif } for ( i in v ) { @if ( T ) print("hello") @endif }
This commit is contained in:
parent
6721248da5
commit
171846a37a
16 changed files with 124 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/at-if-else-if-no-way.zeek, line 12: incorrect use of directive
|
|
@ -0,0 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
2
testing/btest/Baseline/language.at-if-reject-2/.stderr
Normal file
2
testing/btest/Baseline/language.at-if-reject-2/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/at-if-reject.zeek, line 6: incorrect use of directive
|
2
testing/btest/Baseline/language.at-if-reject-3/.stderr
Normal file
2
testing/btest/Baseline/language.at-if-reject-3/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/at-if-reject.zeek, line 5: incorrect use of directive
|
2
testing/btest/Baseline/language.at-if-reject-4/.stderr
Normal file
2
testing/btest/Baseline/language.at-if-reject-4/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/at-if-reject.zeek, line 5: incorrect use of directive
|
2
testing/btest/Baseline/language.at-if-reject-5/.stderr
Normal file
2
testing/btest/Baseline/language.at-if-reject-5/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/at-if-reject.zeek, line 6: incorrect use of directive
|
3
testing/btest/Baseline/language.at-if-reject/.stderr
Normal file
3
testing/btest/Baseline/language.at-if-reject/.stderr
Normal file
|
@ -0,0 +1,3 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/at-if-reject.zeek, line 9: incorrect use of directive
|
||||
error in <...>/at-if-reject.zeek, line 13: syntax error, at or near "else"
|
14
testing/btest/language/at-if-else-if-no-way.zeek
Normal file
14
testing/btest/language/at-if-else-if-no-way.zeek
Normal file
|
@ -0,0 +1,14 @@
|
|||
# @TEST-DOC: Regression test for #2289 from vpax - previously this printed "There's way this should happen", now it's a syntax error.
|
||||
# @TEST-EXEC-FAIL: zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-diff .stdout
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
@if ( T )
|
||||
if ( F )
|
||||
@else
|
||||
if ( F )
|
||||
@endif
|
||||
print "There's no way this should happen";
|
||||
}
|
57
testing/btest/language/at-if-reject.zeek
Normal file
57
testing/btest/language/at-if-reject.zeek
Normal file
|
@ -0,0 +1,57 @@
|
|||
# @TEST-DOC: Test for #2289 - reject directives appearing as statements
|
||||
# @TEST-EXEC-FAIL: zeek -b %INPUT
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
if ( F )
|
||||
@if ( T )
|
||||
print "Bad branch true";
|
||||
@else
|
||||
print "Bad branch false";
|
||||
@endif
|
||||
else
|
||||
print "That's the right branch";
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
if ( F )
|
||||
print "That would be okay";
|
||||
else
|
||||
@if ( T )
|
||||
print "That isn't";
|
||||
@endif
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
local vec = vector(1, 2, 3);
|
||||
for ( i in vec )
|
||||
@if ( T )
|
||||
print "Bad branch true";
|
||||
@endif
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
local i = 10;
|
||||
while ( --i != 0 )
|
||||
@if ( T )
|
||||
print "Bad branch true";
|
||||
@endif
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
global cond = T;
|
||||
event zeek_init()
|
||||
{
|
||||
local vec = vector(1, 2, 3);
|
||||
for ( i in vec )
|
||||
@if ( cond )
|
||||
print "Bad branch true";
|
||||
@endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue