diff options
| author | Jeff Epler <jepler@gmail.com> | 2020-03-01 09:38:34 -0600 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2020-03-01 09:38:34 -0600 |
| commit | 511c1808699ef29908ab99180866c46dfeae4b95 (patch) | |
| tree | d82beec68bfeb2e33fcbcc52c0fea2da729d0d1c /py | |
| parent | 0c2894c72548a08d58e6cf300927e076f9331350 (diff) | |
parse: push_result_token: throw an exception on too-long names
Before this, such names would instead cause an assertion error inside
qstr_from_strn.
A simple reproducer is a python source file containing the letter "a"
repeated 256 times
Diffstat (limited to 'py')
| -rw-r--r-- | py/parse.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/py/parse.c b/py/parse.c index 911b891e0..864528470 100644 --- a/py/parse.c +++ b/py/parse.c @@ -477,6 +477,9 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { mp_parse_node_t pn; mp_lexer_t *lex = parser->lexer; if (lex->tok_kind == MP_TOKEN_NAME) { + if(lex->vstr.len >= (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN))) { + mp_raise_msg(&mp_type_SyntaxError, translate("Name too long")); + } qstr id = qstr_from_strn(lex->vstr.buf, lex->vstr.len); #if MICROPY_COMP_CONST // if name is a standalone identifier, look it up in the table of dynamic constants |
