summaryrefslogtreecommitdiff
path: root/extmod/vfs_reader.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 /extmod/vfs_reader.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 'extmod/vfs_reader.c')
-rw-r--r--extmod/vfs_reader.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/extmod/vfs_reader.c b/extmod/vfs_reader.c
index d3904c5c5..3c6ff52a9 100644
--- a/extmod/vfs_reader.c
+++ b/extmod/vfs_reader.c
@@ -69,10 +69,10 @@ STATIC void mp_reader_vfs_close(void *data) {
m_del_obj(mp_reader_vfs_t, reader);
}
-void mp_reader_new_file(mp_reader_t *reader, const char *filename) {
+void mp_reader_new_file(mp_reader_t *reader, qstr filename) {
mp_reader_vfs_t *rf = m_new_obj(mp_reader_vfs_t);
mp_obj_t args[2] = {
- mp_obj_new_str(filename, strlen(filename)),
+ MP_OBJ_NEW_QSTR(filename),
MP_OBJ_NEW_QSTR(MP_QSTR_rb),
};
rf->file = mp_vfs_open(MP_ARRAY_SIZE(args), &args[0], (mp_map_t *)&mp_const_empty_map);