mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 15:18:20 +00:00
fixes to limit AST traversal in the face of recursive types
This commit is contained in:
parent
910a2f6c59
commit
691a4003b7
2 changed files with 20 additions and 0 deletions
|
@ -58,6 +58,15 @@ public:
|
||||||
return TC_CONTINUE;
|
return TC_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TraversalCode PreType(const Type* t) override {
|
||||||
|
if ( types_seen.count(t) > 0 )
|
||||||
|
return TC_ABORTSTMT;
|
||||||
|
|
||||||
|
types_seen.insert(t);
|
||||||
|
|
||||||
|
return TC_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
void SetHookDepth(int hd) { hook_depth = hd; }
|
void SetHookDepth(int hd) { hook_depth = hd; }
|
||||||
|
|
||||||
bool IsValid() const { return valid_script; }
|
bool IsValid() const { return valid_script; }
|
||||||
|
@ -83,6 +92,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<StmtTag, int> stmt_depths;
|
std::unordered_map<StmtTag, int> stmt_depths;
|
||||||
|
std::unordered_set<const Type*> types_seen;
|
||||||
int hook_depth = 0;
|
int hook_depth = 0;
|
||||||
bool report; // whether to report problems via "reporter"
|
bool report; // whether to report problems via "reporter"
|
||||||
bool valid_script = true;
|
bool valid_script = true;
|
||||||
|
|
|
@ -24,6 +24,13 @@ public:
|
||||||
TraversalCode PreExpr(const Expr*) override;
|
TraversalCode PreExpr(const Expr*) override;
|
||||||
TraversalCode PostExpr(const Expr*) override;
|
TraversalCode PostExpr(const Expr*) override;
|
||||||
|
|
||||||
|
TraversalCode PreType(const Type* t) override {
|
||||||
|
if ( types_seen.count(t) > 0 )
|
||||||
|
return TC_ABORTSTMT;
|
||||||
|
types_seen.insert(t);
|
||||||
|
return TC_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the ultimate verdict re safety.
|
// Returns the ultimate verdict re safety.
|
||||||
bool IsValid() const {
|
bool IsValid() const {
|
||||||
if ( ! is_valid )
|
if ( ! is_valid )
|
||||||
|
@ -105,6 +112,9 @@ protected:
|
||||||
//
|
//
|
||||||
// A count to allow for nesting.
|
// A count to allow for nesting.
|
||||||
int in_aggr_mod_expr = 0;
|
int in_aggr_mod_expr = 0;
|
||||||
|
|
||||||
|
// Used to limit traversal of recursive types.
|
||||||
|
std::unordered_set<const Type*> types_seen;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used for debugging, to communicate which expression wasn't
|
// Used for debugging, to communicate which expression wasn't
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue