njs: Long parentheses string segfault.
printf "%0.s(" {1..6546} | ./build/njs -
Segmentation fault
repeated {, [ and ` are also affected.
About this issue
- Original URL
 - State: closed
 - Created 5 years ago
 - Comments: 18 (17 by maintainers)
 
Commits related to this issue
- Limiting recursion depth while compiling. This closes #146 issue on Github. — committed to nginx/njs by xeioex 5 years ago
 - Limiting recursion depth while compiling unary expressions. This extends 8057f3ad56c1 and is related to #146 issue on Github. — committed to nginx/njs by xeioex 5 years ago
 
@hongzhidao @drsm
Take a look: https://gist.github.com/7df5712ed64a7186cf43d80c7fdf95fb It should protect from any deep recursion in parser or generator. (
printf "%0.s1;" {1..40000} | ./build/njs -is a separate issue)The second issue with the original patch was:
count++andcount--was not paired for all code branches, socountcan became inconsistent (it tended to always to grow).@hongzhidao
printf "%0.s\`" {1..90000} | ./build/njs -should be limited in generator not parser. On it.the same:
@xeioex Think about refactoring out two macros.
@hongzhidao
(,{,[,{[,{;are fine. Thanks!Also found:
@drsm @hongzhidao
I like this variant, because it what we already have for function recursion and this is what V8 does.
Updated.
@xeioex It seems it’s better to commit this patch with
new Functionpatch.@hongzhidao
I reproduced with a larger constant:
BTW, except for
(,{,[, files with long strings of`can also cause the segfault.