Skip to content

Commit 511c180

Browse files
committed
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
1 parent 0c2894c commit 511c180

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

py/parse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) {
477477
mp_parse_node_t pn;
478478
mp_lexer_t *lex = parser->lexer;
479479
if (lex->tok_kind == MP_TOKEN_NAME) {
480+
if(lex->vstr.len >= (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN))) {
481+
mp_raise_msg(&mp_type_SyntaxError, translate("Name too long"));
482+
}
480483
qstr id = qstr_from_strn(lex->vstr.buf, lex->vstr.len);
481484
#if MICROPY_COMP_CONST
482485
// if name is a standalone identifier, look it up in the table of dynamic constants

0 commit comments

Comments
 (0)