8000 tests: Fix all file ioctl's to support only MP_STREAM_CLOSE. · 32bitmicro/micropython@a3128f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a3128f8

Browse files
committed
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>
1 parent 4e76acc commit a3128f8

File tree

8 files changed

+24
-8
lines changed

8 files changed

+24
-8
lines changed

tests/micropython/builtin_execfile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def __init__(self, data):
1616
self.off = 0
1717

1818
def ioctl(self, request, arg):
19-
return 0
19+
if request == 4: # MP_STREAM_CLOSE
20+
return 0
21+
return -1
2022

2123
def readinto(self, buf):
2224
buf[:] = memoryview(self.data)[self.off : self.off + len(buf)]

tests/micropython/import_mpy_invalid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def readinto(self, buf):
2222
return n
2323

2424
def ioctl(self, req, arg):
25-
return 0
25+
if req == 4: # MP_STREAM_CLOSE
26+
return 0
27+
return -1
2628

2729

2830
class UserFS:

tests/micropython/import_mpy_native.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def readinto(self, buf):
2828
return n
2929

3030
def ioctl(self, req, arg):
31-
return 0
31+
if req == 4: # MP_STREAM_CLOSE
32+
return 0
33+
return -1
3234

3335

3436
class UserFS:

tests/micropython/import_mpy_native_gc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def readinto(self, buf):
2222
return n
2323

2424
def ioctl(self, req, arg):
25-
return 0
25+
if req == 4: # MP_STREAM_CLOSE
26+
return 0
27+
return -1
2628

2729

2830
class UserFS:

tests/perf_bench/core_import_mpy_multi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def __init__(self):
3131
self.off = 0
3232

3333
def ioctl(self, request, arg):
34-
return 0
34+
if request == 4: # MP_STREAM_CLOSE
35+
return 0
36+
return -1
3537

3638
def readinto(self, buf):
3739
buf[:] = memoryview(file_data)[self.off : self.off + len(buf)]

tests/perf_bench/core_import_mpy_single.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def __init__(self):
8686
self.off = 0
8787

8888
def ioctl(self, request, arg):
89-
return 0
89+
if request == 4: # MP_STREAM_CLOSE
90+
return 0
91+
return -1
9092

9193
def readinto(self, buf):
9294
buf[:] = memoryview(file_data)[self.off : self.off + len(buf)]

tests/run-natmodtests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class __File(io.IOBase):
3535
def __init__(self):
3636
self.off = 0
3737
def ioctl(self, request, arg):
38-
return 0
38+
if request == 4: # MP_STREAM_CLOSE
39+
return 0
40+
return -1
3941
def readinto(self, buf):
4042
buf[:] = memoryview(__buf)[self.off:self.off + len(buf)]
4143
self.off += len(buf)

tests/run-tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def __init__(self):
6868
sys.modules['__injected_test'].__name__ = '__main__'
6969
self.off = 0
7070
def ioctl(self, request, arg):
71-
return 0
71+
if request == 4: # MP_STREAM_CLOSE
72+
return 0
73+
return -1
7274
def readinto(self, buf):
7375
buf[:] = memoryview(__buf)[self.off:self.off + len(buf)]
7476
self.off += len(buf)

0 commit comments

Comments
 (0)
0