From c6ae322f858ded60ac4660f7b586e47a503d20d9 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 2 Aug 2020 17:58:05 +0300 Subject: [PATCH] parser: add hard limit to the number of statements in a fn --- vlib/v/parser/parser.v | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index dd926fce0e..2a88143497 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -321,12 +321,21 @@ pub fn (mut p Parser) parse_block_no_scope(is_top_level bool) []ast.Stmt { p.check(.lcbr) mut stmts := []ast.Stmt{} if p.tok.kind != .rcbr { + mut c := 0 for { stmts << p.stmt(is_top_level) // p.warn('after stmt(): tok=$p.tok.str()') if p.tok.kind in [.eof, .rcbr] { break } + c++ + if c % 100000 == 0 { + eprintln('parsed $c statements so far from fn $p.cur_fn_name ...') + } + if c > 1000000 { + p.error_with_pos('parsed over $c statements from fn $p.cur_fn_name, the parser is probably stuck', + p.tok.position()) + } } } if is_top_level {