mirror of
https://github.com/micropython/micropython.git
synced 2025-12-15 17:30:14 +01:00
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>
This commit is contained in:
committed by
Damien George
parent
adf6319884
commit
4b013ec3ff
@@ -83,7 +83,7 @@ void mp_reader_new_file(mp_reader_t *reader, qstr filename) {
|
||||
};
|
||||
mp_obj_t file = mp_vfs_open(MP_ARRAY_SIZE(args), &args[0], (mp_map_t *)&mp_const_empty_map);
|
||||
|
||||
const mp_stream_p_t *stream_p = mp_get_stream(file);
|
||||
const mp_stream_p_t *stream_p = mp_get_stream_raise(file, MP_STREAM_OP_READ);
|
||||
int errcode = 0;
|
||||
|
||||
#if MICROPY_VFS_ROM
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -5,3 +5,6 @@ open /test.py rb
|
||||
123
|
||||
TypeError
|
||||
umount
|
||||
mount False False
|
||||
OSError
|
||||
umount
|
||||
|
||||
Reference in New Issue
Block a user