summaryrefslogtreecommitdiff
path: root/shared
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 /shared
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 'shared')
-rw-r--r--shared/memzip/lexermemzip.c6
-rw-r--r--shared/runtime/pyexec.c2
2 files changed, 4 insertions, 4 deletions
diff --git a/shared/memzip/lexermemzip.c b/shared/memzip/lexermemzip.c
index 6b26961bd..1915a04c0 100644
--- a/shared/memzip/lexermemzip.c
+++ b/shared/memzip/lexermemzip.c
@@ -5,15 +5,15 @@
#include "py/mperrno.h"
#include "memzip.h"
-mp_lexer_t *mp_lexer_new_from_file(const char *filename)
+mp_lexer_t *mp_lexer_new_from_file(qstr filename)
{
void *data;
size_t len;
- if (memzip_locate(filename, &data, &len) != MZ_OK) {
+ if (memzip_locate(qstr_str(filename), &data, &len) != MZ_OK) {
mp_raise_OSError(MP_ENOENT);
}
- return mp_lexer_new_from_str_len(qstr_from_str(filename), (const char *)data, (mp_uint_t)len, 0);
+ return mp_lexer_new_from_str_len(filename, (const char *)data, (mp_uint_t)len, 0);
}
diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c
index e32150e5e..9f6d9a100 100644
--- a/shared/runtime/pyexec.c
+++ b/shared/runtime/pyexec.c
@@ -100,7 +100,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
} else if (exec_flags & EXEC_FLAG_SOURCE_IS_READER) {
lex = mp_lexer_new(MP_QSTR__lt_stdin_gt_, *(mp_reader_t *)source);
} else if (exec_flags & EXEC_FLAG_SOURCE_IS_FILENAME) {
- lex = mp_lexer_new_from_file(source);
+ lex = mp_lexer_new_from_file(qstr_from_str(source));
} else {
lex = (mp_lexer_t *)source;
}