mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 01:28:20 +00:00
Fix three bugs with 'when' and 'return when' statements. Addresses #946
- 'when' statements were problematic when used in a function/event/hook that had local variables with an assigned function value. This was because 'when' blocks operate on a clone of the frame and the cloning process serializes locals and the serialization of functions had an infinite cycle in it (ID -> BroFunc -> ID -> BroFunc ...). The ID was only used for the function name and type information, so refactoring Func and subclasses to depend on those two things instead fixes the issue. - 'return when' blocks, specifically, didn't work whenever execution of the containing function's body does another function call before reaching the 'return when' block, because of an assertion. This was was due to logic in CallExpr::Eval always clearing the CallExpr associated with the Frame after doing the call, instead of restoring any previous CallExpr, which the code in Trigger::Eval expected to have available. - An assert could be reached when the condition of a 'when' statement depended on checking the value of global state variables. The assert in Trigger::QueueTrigger that checks that the Trigger isn't disabled would get hit because Trigger::Eval/Timeout disable themselves after running, but don't unregister themselves from the NotifierRegistry, which keeps calling QueueTrigger for every state access of the global.
This commit is contained in:
parent
a2556642e6
commit
7e5115460c
11 changed files with 144 additions and 63 deletions
17
src/Func.h
17
src/Func.h
|
@ -47,15 +47,11 @@ public:
|
|||
virtual void SetScope(Scope* newscope) { scope = newscope; }
|
||||
virtual Scope* GetScope() const { return scope; }
|
||||
|
||||
virtual FuncType* FType() const
|
||||
{
|
||||
return (FuncType*) id->Type()->AsFuncType();
|
||||
}
|
||||
virtual FuncType* FType() const { return type->AsFuncType(); }
|
||||
|
||||
Kind GetKind() const { return kind; }
|
||||
|
||||
const ID* GetID() const { return id; }
|
||||
void SetID(ID *arg_id);
|
||||
const char* Name() const { return name.c_str(); }
|
||||
|
||||
virtual void Describe(ODesc* d) const = 0;
|
||||
virtual void DescribeDebug(ODesc* d, const val_list* args) const;
|
||||
|
@ -64,7 +60,6 @@ public:
|
|||
bool Serialize(SerialInfo* info) const;
|
||||
static Func* Unserialize(UnserialInfo* info);
|
||||
|
||||
ID* GetReturnValueID() const;
|
||||
virtual TraversalCode Traverse(TraversalCallback* cb) const;
|
||||
|
||||
uint32 GetUniqueFuncID() const { return unique_id; }
|
||||
|
@ -79,8 +74,8 @@ protected:
|
|||
vector<Body> bodies;
|
||||
Scope* scope;
|
||||
Kind kind;
|
||||
ID* id;
|
||||
ID* return_value;
|
||||
BroType* type;
|
||||
string name;
|
||||
uint32 unique_id;
|
||||
static vector<Func*> unique_ids;
|
||||
};
|
||||
|
@ -119,18 +114,16 @@ public:
|
|||
|
||||
int IsPure() const;
|
||||
Val* Call(val_list* args, Frame* parent) const;
|
||||
const char* Name() const { return name; }
|
||||
built_in_func TheFunc() const { return func; }
|
||||
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
protected:
|
||||
BuiltinFunc() { func = 0; name = 0; is_pure = 0; }
|
||||
BuiltinFunc() { func = 0; is_pure = 0; }
|
||||
|
||||
DECLARE_SERIAL(BuiltinFunc);
|
||||
|
||||
built_in_func func;
|
||||
const char* name;
|
||||
int is_pure;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue