diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-09-02 16:44:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 16:44:19 (GMT) |
commit | 4a97b1517a6b5ff22e2984b677a680b07ff0ce11 (patch) | |
tree | d31c9d8aa26544863790e5643c79c10e0172f0c3 /Grammar/python.gram | |
parent | 3940333637b98a2781869977b077552514784529 (diff) | |
download | cpython-4a97b1517a6b5ff22e2984b677a680b07ff0ce11.zip cpython-4a97b1517a6b5ff22e2984b677a680b07ff0ce11.tar.gz cpython-4a97b1517a6b5ff22e2984b677a680b07ff0ce11.tar.bz2 |
bpo-41690: Use a loop to collect args in the parser instead of recursion (GH-22053)
This program can segfault the parser by stack overflow:
```
import ast
code = "f(" + ",".join(['a' for _ in range(100000)]) + ")"
print("Ready!")
ast.parse(code)
```
the reason is that the rule for arguments has a simple recursion when collecting args:
args[expr_ty]:
[...]
| a=named_expression b=[',' c=args { c }] {
[...] }
Diffstat (limited to 'Grammar/python.gram')
-rw-r--r-- | Grammar/python.gram | 13 |
1 files changed, 1 insertions, 12 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 1cba114..84835b7 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -535,22 +535,11 @@ arguments[expr_ty] (memo): | a=args [','] &')' { a } | incorrect_arguments args[expr_ty]: - | a=starred_expression b=[',' c=args { c }] { - _Py_Call(_PyPegen_dummy_name(p), - (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) - : CHECK(_PyPegen_singleton_seq(p, a)), - (b) ? ((expr_ty) b)->v.Call.keywords : NULL, - EXTRA) } + | a=','.(starred_expression | named_expression !'=')+ b=[',' k=kwargs {k}] { _PyPegen_collect_call_seqs(p, a, b) } | a=kwargs { _Py_Call(_PyPegen_dummy_name(p), CHECK_NULL_ALLOWED(_PyPegen_seq_extract_starred_exprs(p, a)), CHECK_NULL_ALLOWED(_PyPegen_seq_delete_starred_exprs(p, a)), EXTRA) } - | a=named_expression b=[',' c=args { c }] { - _Py_Call(_PyPegen_dummy_name(p), - (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) - : CHECK(_PyPegen_singleton_seq(p, a)), - (b) ? ((expr_ty) b)->v.Call.keywords : NULL, - EXTRA) } kwargs[asdl_seq*]: | a=','.kwarg_or_starred+ ',' b=','.kwarg_or_double_starred+ { _PyPegen_join_sequences(p, a, b) } | ','.kwarg_or_starred+ |