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:
@@ -16,7 +16,9 @@ class File(io.IOBase):
|
|||||||
self.off = 0
|
self.off = 0
|
||||||
|
|
||||||
def ioctl(self, request, arg):
|
def ioctl(self, request, arg):
|
||||||
|
if request == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
|
|
||||||
def readinto(self, buf):
|
def readinto(self, buf):
|
||||||
buf[:] = memoryview(self.data)[self.off : self.off + len(buf)]
|
buf[:] = memoryview(self.data)[self.off : self.off + len(buf)]
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ class UserFile(io.IOBase):
|
|||||||
return n
|
return n
|
||||||
|
|
||||||
def ioctl(self, req, arg):
|
def ioctl(self, req, arg):
|
||||||
|
if req == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
class UserFS:
|
class UserFS:
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ class UserFile(io.IOBase):
|
|||||||
return n
|
return n
|
||||||
|
|
||||||
def ioctl(self, req, arg):
|
def ioctl(self, req, arg):
|
||||||
|
if req == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
class UserFS:
|
class UserFS:
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ class UserFile(io.IOBase):
|
|||||||
return n
|
return n
|
||||||
|
|
||||||
def ioctl(self, req, arg):
|
def ioctl(self, req, arg):
|
||||||
|
if req == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
class UserFS:
|
class UserFS:
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ class File(io.IOBase):
|
|||||||
self.off = 0
|
self.off = 0
|
||||||
|
|
||||||
def ioctl(self, request, arg):
|
def ioctl(self, request, arg):
|
||||||
|
if request == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
|
|
||||||
def readinto(self, buf):
|
def readinto(self, buf):
|
||||||
buf[:] = memoryview(file_data)[self.off : self.off + len(buf)]
|
buf[:] = memoryview(file_data)[self.off : self.off + len(buf)]
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ class File(io.IOBase):
|
|||||||
self.off = 0
|
self.off = 0
|
||||||
|
|
||||||
def ioctl(self, request, arg):
|
def ioctl(self, request, arg):
|
||||||
|
if request == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
|
|
||||||
def readinto(self, buf):
|
def readinto(self, buf):
|
||||||
buf[:] = memoryview(file_data)[self.off : self.off + len(buf)]
|
buf[:] = memoryview(file_data)[self.off : self.off + len(buf)]
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ class __File(io.IOBase):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.off = 0
|
self.off = 0
|
||||||
def ioctl(self, request, arg):
|
def ioctl(self, request, arg):
|
||||||
|
if request == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
def readinto(self, buf):
|
def readinto(self, buf):
|
||||||
buf[:] = memoryview(__buf)[self.off:self.off + len(buf)]
|
buf[:] = memoryview(__buf)[self.off:self.off + len(buf)]
|
||||||
self.off += len(buf)
|
self.off += len(buf)
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ class __File(io.IOBase):
|
|||||||
sys.modules['__injected_test'].__name__ = '__main__'
|
sys.modules['__injected_test'].__name__ = '__main__'
|
||||||
self.off = 0
|
self.off = 0
|
||||||
def ioctl(self, request, arg):
|
def ioctl(self, request, arg):
|
||||||
|
if request == 4: # MP_STREAM_CLOSE
|
||||||
return 0
|
return 0
|
||||||
|
return -1
|
||||||
def readinto(self, buf):
|
def readinto(self, buf):
|
||||||
buf[:] = memoryview(__buf)[self.off:self.off + len(buf)]
|
buf[:] = memoryview(__buf)[self.off:self.off + len(buf)]
|
||||||
self.off += len(buf)
|
self.off += len(buf)
|
||||||
|
|||||||
Reference in New Issue
Block a user