mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
ast: protect against too deep recursion in Expr.pos() calls
This commit is contained in:
parent
911428cd5f
commit
7d81633912
1 changed files with 16 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
|
// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
|
||||||
// Use of this source code is governed by an MIT license
|
// Use of this source code is governed by an MIT license
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
|
@[has_globals]
|
||||||
module ast
|
module ast
|
||||||
|
|
||||||
import v.token
|
import v.token
|
||||||
|
@ -2094,10 +2095,25 @@ pub fn (expr Expr) is_blank_ident() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__global nested_expr_pos_calls = 0
|
||||||
|
// values above 14000 risk stack overflow by default on macos in Expr.pos() calls
|
||||||
|
const max_nested_expr_pos_calls = 5000
|
||||||
|
|
||||||
pub fn (expr Expr) pos() token.Pos {
|
pub fn (expr Expr) pos() token.Pos {
|
||||||
// all uncommented have to be implemented
|
// all uncommented have to be implemented
|
||||||
// Note: please do not print here. the language server will hang
|
// Note: please do not print here. the language server will hang
|
||||||
// as it uses STDIO primarily to communicate ~Ned
|
// as it uses STDIO primarily to communicate ~Ned
|
||||||
|
nested_expr_pos_calls++
|
||||||
|
if nested_expr_pos_calls > ast.max_nested_expr_pos_calls {
|
||||||
|
$if panic_on_deeply_nested_expr_pos_calls ? {
|
||||||
|
eprintln('${@LOCATION}: too many nested Expr.pos() calls: ${nested_expr_pos_calls}, expr type: ${expr.type_name()}')
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
return token.Pos{}
|
||||||
|
}
|
||||||
|
defer {
|
||||||
|
nested_expr_pos_calls--
|
||||||
|
}
|
||||||
return match expr {
|
return match expr {
|
||||||
AnonFn {
|
AnonFn {
|
||||||
expr.decl.pos
|
expr.decl.pos
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue