mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
Interpreter exceptions occurring in "when" blocks are now handled.
The scripting error that caused the exception is still reported, but it no longer causes Bro to terminate. Addresses #779
This commit is contained in:
parent
05e6289719
commit
f7440375f1
3 changed files with 92 additions and 3 deletions
|
@ -217,8 +217,15 @@ bool Trigger::Eval()
|
||||||
Name());
|
Name());
|
||||||
|
|
||||||
Unref(v);
|
Unref(v);
|
||||||
|
v = 0;
|
||||||
stmt_flow_type flow;
|
stmt_flow_type flow;
|
||||||
v = body->Exec(f, flow);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
v = body->Exec(f, flow);
|
||||||
|
}
|
||||||
|
catch ( InterpreterException& e )
|
||||||
|
{ /* Already reported. */ }
|
||||||
|
|
||||||
if ( is_return )
|
if ( is_return )
|
||||||
{
|
{
|
||||||
|
@ -300,7 +307,14 @@ void Trigger::Timeout()
|
||||||
{
|
{
|
||||||
stmt_flow_type flow;
|
stmt_flow_type flow;
|
||||||
Frame* f = frame->Clone();
|
Frame* f = frame->Clone();
|
||||||
Val* v = timeout_stmts->Exec(f, flow);
|
Val* v = 0;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
v = timeout_stmts->Exec(f, flow);
|
||||||
|
}
|
||||||
|
catch ( InterpreterException& e )
|
||||||
|
{ /* Already reported. */ }
|
||||||
|
|
||||||
if ( is_return )
|
if ( is_return )
|
||||||
{
|
{
|
||||||
|
@ -382,7 +396,7 @@ void Trigger::Attach(Trigger *trigger)
|
||||||
|
|
||||||
void Trigger::Cache(const CallExpr* expr, Val* v)
|
void Trigger::Cache(const CallExpr* expr, Val* v)
|
||||||
{
|
{
|
||||||
if ( disabled )
|
if ( disabled || ! v )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ValCache::iterator i = cache.find(expr);
|
ValCache::iterator i = cache.find(expr);
|
||||||
|
|
12
testing/btest/Baseline/core.dns-interpreter-exceptions/out
Normal file
12
testing/btest/Baseline/core.dns-interpreter-exceptions/out
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
1300475167.096535 expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.dns-interpreter-exceptions/dns-interpreter-exceptions.bro, line 28: field value missing [p$ip]
|
||||||
|
1300475167.096535 expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.dns-interpreter-exceptions/dns-interpreter-exceptions.bro, line 49: field value missing [p$ip]
|
||||||
|
1300475168.902195 expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.dns-interpreter-exceptions/dns-interpreter-exceptions.bro, line 39: field value missing [p$ip]
|
||||||
|
1300475168.902195 expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.dns-interpreter-exceptions/dns-interpreter-exceptions.bro, line 12: field value missing [p$ip]
|
||||||
|
timeout g(), F
|
||||||
|
timeout g(), T
|
||||||
|
timeout
|
||||||
|
g() done, no exception, T
|
||||||
|
localhost resolved
|
||||||
|
localhost resolved from f(), T
|
||||||
|
localhost resolved from f(), F
|
||||||
|
f() done, no exception, T
|
63
testing/btest/core/dns-interpreter-exceptions.bro
Normal file
63
testing/btest/core/dns-interpreter-exceptions.bro
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
# @TEST-EXEC: bro -b -r $TRACES/wikipedia.trace %INPUT >out 2>&1
|
||||||
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||||
|
# interpreter exceptions in "when" blocks shouldn't cause termination
|
||||||
|
global p: pkt_hdr;
|
||||||
|
|
||||||
|
function f(do_exception: bool): bool
|
||||||
|
{
|
||||||
|
return when ( local addrs = lookup_hostname("localhost") )
|
||||||
|
{
|
||||||
|
print "localhost resolved from f()", do_exception;
|
||||||
|
if ( do_exception )
|
||||||
|
print p$ip;
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
return F;
|
||||||
|
}
|
||||||
|
|
||||||
|
function g(do_exception: bool): bool
|
||||||
|
{
|
||||||
|
return when ( local addrs = lookup_hostname("localhost") )
|
||||||
|
{
|
||||||
|
print "shouldn't get here, g()", do_exception;
|
||||||
|
}
|
||||||
|
timeout 0 sec
|
||||||
|
{
|
||||||
|
print "timeout g()", do_exception;
|
||||||
|
if ( do_exception )
|
||||||
|
print p$ip;
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
return F;
|
||||||
|
}
|
||||||
|
|
||||||
|
event bro_init()
|
||||||
|
{
|
||||||
|
when ( local addrs = lookup_hostname("localhost") )
|
||||||
|
{
|
||||||
|
print "localhost resolved";
|
||||||
|
print p$ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
when ( local addrs2 = lookup_hostname("localhost") )
|
||||||
|
{
|
||||||
|
print "shouldn't get here";
|
||||||
|
}
|
||||||
|
timeout 0 sec
|
||||||
|
{
|
||||||
|
print "timeout";
|
||||||
|
print p$ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
when ( local b = f(T) )
|
||||||
|
print "f() exception done (shouldn't be printed)", b;
|
||||||
|
|
||||||
|
when ( local b2 = g(T) )
|
||||||
|
print "g() exception done (shouldn't be printed)", b2;
|
||||||
|
|
||||||
|
when ( local b3 = f(F) )
|
||||||
|
print "f() done, no exception", b3;
|
||||||
|
|
||||||
|
when ( local b4 = g(F) )
|
||||||
|
print "g() done, no exception", b4;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue