diff options
| author | Jeff Epler <jepler@gmail.com> | 2025-08-08 08:53:14 -0500 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-09-28 22:45:30 +1000 |
| commit | 4b013ec3ff688b8dc3af0cc9159a5fc4c27d8d20 (patch) | |
| tree | 36804b9e37aabd49f78614e2ab952740b21f7ec0 /tests/micropython/builtin_execfile.py | |
| parent | adf63198849caa8c660249782caa368589ef7916 (diff) | |
extmod/vfs_reader: Check that open() resulted in a file-like object.
That is, an object whose type defines the protocol slot.
Note that due to protocol confusion, a variant of the original crasher that
returned e.g., a machine.Pin instance could still lead to a crash (#17852).
Fixes issue #17841.
Signed-off-by: Jeff Epler <jepler@gmail.com>
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
Diffstat (limited to 'tests/micropython/builtin_execfile.py')
| -rw-r--r-- | tests/micropython/builtin_execfile.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/micropython/builtin_execfile.py b/tests/micropython/builtin_execfile.py index 75a867bb9..4fd4d66d4 100644 --- a/tests/micropython/builtin_execfile.py +++ b/tests/micropython/builtin_execfile.py @@ -75,3 +75,24 @@ except TypeError: # Unmount the VFS object. vfs.umount(fs) + + +class EvilFilesystem: + def mount(self, readonly, mkfs): + print("mount", readonly, mkfs) + + def umount(self): + print("umount") + + def open(self, file, mode): + return None + + +fs = EvilFilesystem() +vfs.mount(fs, "/test_mnt") +try: + execfile("/test_mnt/test.py") + print("ExecFile succeeded") +except OSError: + print("OSError") +vfs.umount(fs) |
