From 511c1808699ef29908ab99180866c46dfeae4b95 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 1 Mar 2020 09:38:34 -0600 Subject: [PATCH] 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 --- py/parse.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/py/parse.c b/py/parse.c index 911b891e0f..864528470f 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