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>
This commit is contained in:
committed by
Damien George
parent
480659b1ac
commit
5015779a6f
@@ -302,8 +302,8 @@ soft_reset:
|
||||
#if !MICROPY_VFS
|
||||
#if MICROPY_MBFS
|
||||
// Use micro:bit filesystem
|
||||
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
|
||||
return os_mbfs_new_reader(filename);
|
||||
mp_lexer_t *mp_lexer_new_from_file(qstr filename) {
|
||||
return os_mbfs_new_reader(qstr_str(filename));
|
||||
}
|
||||
|
||||
mp_import_stat_t mp_import_stat(const char *path) {
|
||||
@@ -317,7 +317,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
#else
|
||||
// use dummy functions - no filesystem available
|
||||
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
|
||||
mp_lexer_t *mp_lexer_new_from_file(qstr filename) {
|
||||
mp_raise_OSError(MP_ENOENT);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user