summaryrefslogtreecommitdiff
path: root/mpy-cross/main.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 /mpy-cross/main.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 'mpy-cross/main.c')
-rw-r--r--mpy-cross/main.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/mpy-cross/main.c b/mpy-cross/main.c
index 3ef77d436..f05aef5dd 100644
--- a/mpy-cross/main.c
+++ b/mpy-cross/main.c
@@ -71,7 +71,7 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
if (strcmp(file, "-") == 0) {
lex = mp_lexer_new_from_fd(MP_QSTR__lt_stdin_gt_, STDIN_FILENO, false);
} else {
- lex = mp_lexer_new_from_file(file);
+ lex = mp_lexer_new_from_file(qstr_from_str(file));
}
qstr source_name;
@@ -104,7 +104,7 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
vstr_add_str(&vstr, output_file);
}
- mp_raw_code_save_file(&cm, vstr_null_terminated_str(&vstr));
+ mp_raw_code_save_file(&cm, qstr_from_strn(vstr.buf, vstr.len));
vstr_clear(&vstr);
}