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:
Jim Mussared
2023-09-27 13:43:50 +10:00
committed by Damien George
parent 480659b1ac
commit 5015779a6f
25 changed files with 62 additions and 46 deletions

View File

@@ -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)

View File

@@ -3,4 +3,5 @@ open /noexist.py rb
OSError
open /test.py rb
123
TypeError
umount