Skip to content

Commit

Permalink
[DSLX:frontend] Track NameDefTree nesting to avoid deep recursion in …
Browse files Browse the repository at this point in the history
…fuzzing.

PiperOrigin-RevId: 611596733
  • Loading branch information
cdleary authored and copybara-github committed Feb 29, 2024
1 parent 247f2c1 commit a36bf69
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions xls/dslx/frontend/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,16 @@ absl::StatusOr<NameDefTree*> Parser::ParseNameDefTree(Bindings& bindings) {

auto parse_name_def_or_tree = [&bindings,
this]() -> absl::StatusOr<NameDefTree*> {
XLS_ASSIGN_OR_RETURN(bool peek_is_oparen, PeekTokenIs(TokenKind::kOParen));
if (peek_is_oparen) {
XLS_ASSIGN_OR_RETURN(const Token* peek, PeekToken());
if (peek->kind() == TokenKind::kOParen) {
if (++approximate_expression_depth_ >= kApproximateExpressionDepthLimit) {
return ParseErrorStatus(
peek->span(),
"Name definition tree is too deeply nested, please break "
"into multiple statements");
}
auto bump_down =
absl::Cleanup([this] { approximate_expression_depth_--; });
return ParseNameDefTree(bindings);
}
XLS_ASSIGN_OR_RETURN(auto name_def, ParseNameDefOrWildcard(bindings));
Expand Down

0 comments on commit a36bf69

Please sign in to comment.