Fix for a table refering to a expire function that's not defined.

I was hoping to report this right at startup through a static check
but turns out we don't have the right machinery in place for that.
That would need to be done after the AST has been finalized, but our
AST traversal code can't iterate over types. So instead I've changed
this so that it's still being reported at runtime but at least
doesn't crash Bro anymore.

Closes BIT-1597.
This commit is contained in:
Robin Sommer 2016-05-23 12:45:23 -07:00
parent 0fa9590902
commit 4f9cb6912a
5 changed files with 82 additions and 2 deletions

View file

@ -2285,8 +2285,23 @@ double TableVal::CallExpireFunc(Val* idx)
try
{
Val* vs = expire_expr->Eval(0)->AsFunc()->Call(vl);
Val* vf = expire_expr->Eval(0);
if ( ! vf )
// Will have been reported already.
return 0;
if ( vf->Type()->Tag() != TYPE_FUNC )
{
Unref(vf);
vf->Error("not a function");
return 0;
}
Val* vs = vf->AsFunc()->Call(vl);
secs = vs->AsInterval();
Unref(vf);
Unref(vs);
delete vl;
}