summaryrefslogtreecommitdiff
path: root/py/builtinevex.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-09-27 13:43:50 +1000
committerDamien George <damien@micropython.org>2023-10-12 15:17:59 +1100
commit5015779a6f4a180233a78ec8b5fd1ea095057a91 (patch)
treed034986dcc9dde9631838918822cca1ef7f3941a /py/builtinevex.c
parent480659b1ac758c377568c93c0ccda6a232f744ca (diff)
py/builtinevex: Handle invalid filenames for execfile.
If a non-string buffer was passed to execfile, then it would be passed as a non-null-terminated char* to mp_lexer_new_from_file. This changes mp_lexer_new_from_file to take a qstr instead (as in almost all cases a qstr will be created from this input anyway to set the `__file__` attribute on the module). This now makes execfile require a string (not generic buffer) argument, which is probably a good fix to make anyway. Fixes issue #12522. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/builtinevex.c')
-rw-r--r--py/builtinevex.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/py/builtinevex.c b/py/builtinevex.c
index 97eab7fad..73fca5d39 100644
--- a/py/builtinevex.c
+++ b/py/builtinevex.c
@@ -136,17 +136,18 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i
}
#endif
- // Extract the source code.
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
// create the lexer
// MP_PARSE_SINGLE_INPUT is used to indicate a file input
mp_lexer_t *lex;
if (MICROPY_PY_BUILTINS_EXECFILE && parse_input_kind == MP_PARSE_SINGLE_INPUT) {
- lex = mp_lexer_new_from_file(bufinfo.buf);
+ lex = mp_lexer_new_from_file(mp_obj_str_get_qstr(args[0]));
parse_input_kind = MP_PARSE_FILE_INPUT;
} else {
+ // Extract the source code.
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
+
lex = mp_lexer_new_from_str_len(MP_QSTR__lt_string_gt_, bufinfo.buf, bufinfo.len, 0);
}