diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2023-09-27 13:43:50 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-10-12 15:17:59 +1100 |
commit | 5015779a6f4a180233a78ec8b5fd1ea095057a91 (patch) | |
tree | d034986dcc9dde9631838918822cca1ef7f3941a /tests/micropython/builtin_execfile.py | |
parent | 480659b1ac758c377568c93c0ccda6a232f744ca (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 'tests/micropython/builtin_execfile.py')
-rw-r--r-- | tests/micropython/builtin_execfile.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/micropython/builtin_execfile.py b/tests/micropython/builtin_execfile.py index 5a26ccf0a..9b6d6a0aa 100644 --- a/tests/micropython/builtin_execfile.py +++ b/tests/micropython/builtin_execfile.py @@ -70,5 +70,11 @@ except OSError: # Test execfile with a file that does exist. execfile("/test_mnt/test.py") +# Test that it only works with string arguments. +try: + execfile(b"aaa") +except TypeError: + print("TypeError") + # Unmount the VFS object. os.umount(fs) |