mirror of
https://github.com/micropython/micropython.git
synced 2025-08-25 12:00:40 +02:00
tests: Fix all file ioctl's to support only MP_STREAM_CLOSE.
A return value of 0 from Python-level `ioctl()` means success, but if that's returned unconditionally it means that the method supports all ioctl calls, which is not true. Returning 0 without doing anything can potentially lead to a crash, eg for MP_STREAM_SEEK which requires returning a value in the passed-in struct pointer. This commit makes it so that all `ioctl()` methods respond only to MP_STREAM_CLOSE, ie they return -1 (indicating error) for all other ioctl calls. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -68,7 +68,9 @@ class __File(io.IOBase):
|
||||
sys.modules['__injected_test'].__name__ = '__main__'
|
||||
self.off = 0
|
||||
def ioctl(self, request, arg):
|
||||
return 0
|
||||
if request == 4: # MP_STREAM_CLOSE
|
||||
return 0
|
||||
return -1
|
||||
def readinto(self, buf):
|
||||
buf[:] = memoryview(__buf)[self.off:self.off + len(buf)]
|
||||
self.off += len(buf)
|
||||
|
Reference in New Issue
Block a user