summaryrefslogtreecommitdiff
path: root/py/persistentcode.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/persistentcode.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/persistentcode.c')
-rw-r--r--py/persistentcode.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/py/persistentcode.c b/py/persistentcode.c
index e1218e0b8..0feb93bdb 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -451,7 +451,7 @@ void mp_raw_code_load_mem(const byte *buf, size_t len, mp_compiled_module_t *con
#if MICROPY_HAS_FILE_READER
-void mp_raw_code_load_file(const char *filename, mp_compiled_module_t *context) {
+void mp_raw_code_load_file(qstr filename, mp_compiled_module_t *context) {
mp_reader_t reader;
mp_reader_new_file(&reader, filename);
mp_raw_code_load(&reader, context);
@@ -638,12 +638,12 @@ STATIC void fd_print_strn(void *env, const char *str, size_t len) {
(void)ret;
}
-void mp_raw_code_save_file(mp_compiled_module_t *cm, const char *filename) {
+void mp_raw_code_save_file(mp_compiled_module_t *cm, qstr filename) {
MP_THREAD_GIL_EXIT();
- int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ int fd = open(qstr_str(filename), O_WRONLY | O_CREAT | O_TRUNC, 0644);
MP_THREAD_GIL_ENTER();
if (fd < 0) {
- mp_raise_OSError_with_filename(errno, filename);
+ mp_raise_OSError_with_filename(errno, qstr_str(filename));
}
mp_print_t fd_print = {(void *)(intptr_t)fd, fd_print_strn};
mp_raw_code_save(cm, &fd_print);