mirror of
https://github.com/zeek/zeek.git
synced 2025-10-01 22:28:20 +00:00
Merge remote-tracking branch 'origin/topic/awelzel/fix-assert-cond-twice'
* origin/topic/awelzel/fix-assert-cond-twice: Stmt: Fix assert evaluating cond twice
This commit is contained in:
commit
6867eda621
6 changed files with 50 additions and 2 deletions
13
CHANGES
13
CHANGES
|
@ -1,3 +1,16 @@
|
|||
7.0.0-dev.36 | 2024-03-04 18:22:34 +0100
|
||||
|
||||
* Stmt: Fix assert evaluating cond twice (Arne Welzel, Corelight)
|
||||
|
||||
Since 81a9745fb36fb6705873921423364bd2c438bfc4, the assert condition is
|
||||
evaluated twice. This leads to unexpected behavior when cond has a side
|
||||
effect like publishing a message or creating a log stream or filter.
|
||||
|
||||
Found while using the following in ad-hoc testing code and wondering
|
||||
why two messages were published.
|
||||
|
||||
assert publish(Cluster::worker_topic, hello, "abc")
|
||||
|
||||
7.0.0-dev.34 | 2024-03-04 15:49:19 +0100
|
||||
|
||||
* Port Spicy integration to new AST API. (Robin Sommer, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
7.0.0-dev.34
|
||||
7.0.0-dev.36
|
||||
|
|
|
@ -1644,7 +1644,7 @@ ValPtr AssertStmt::Exec(Frame* f, StmtFlowType& flow) {
|
|||
bool run_result_hook = assertion_result_hook && assertion_result_hook->HasEnabledBodies();
|
||||
auto assert_result = cond->Eval(f)->AsBool();
|
||||
|
||||
if ( ! cond->Eval(f)->AsBool() || run_result_hook ) {
|
||||
if ( ! assert_result || run_result_hook ) {
|
||||
zeek::StringValPtr msg_val = zeek::val_mgr->EmptyString();
|
||||
|
||||
if ( msg ) {
|
||||
|
|
1
testing/btest/Baseline/language.assert-hook-8/.stderr
Normal file
1
testing/btest/Baseline/language.assert-hook-8/.stderr
Normal file
|
@ -0,0 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
6
testing/btest/Baseline/language.assert-hook-8/out
Normal file
6
testing/btest/Baseline/language.assert-hook-8/out
Normal file
|
@ -0,0 +1,6 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
zeek_init
|
||||
returning true
|
||||
assertion_result, T, always_true(), always true, <...>/assert-hook.zeek, 23
|
||||
returning false
|
||||
assertion_result, F, always_false(), always false, <...>/assert-hook.zeek, 24
|
|
@ -196,3 +196,31 @@ event zeek_done()
|
|||
assert 2 + 2 == 5, "this is false";
|
||||
print "not reached";
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Ensure cond is only evaluated once.
|
||||
hook assertion_result(result: bool, cond: string, msg: string, bt: Backtrace)
|
||||
{
|
||||
print "assertion_result", result, cond, msg, bt[0]$file_location, bt[0]$line_location;
|
||||
break;
|
||||
}
|
||||
|
||||
function always_true(): bool
|
||||
{
|
||||
print "returning true";
|
||||
return T;
|
||||
}
|
||||
|
||||
function always_false(): bool
|
||||
{
|
||||
print "returning false";
|
||||
return F;
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
print "zeek_init";
|
||||
assert always_true(), "always true";
|
||||
assert always_false(), "always false";
|
||||
print "not reached";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue